由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - 用尽心思做好了一个macro
相关主题
一个SAS Macro和Append的问题,救助!help. sas macro
如何添加时间变量My $0.02 on SAS debugging in Linux environment.
help need for SAS macroHow to set initial dataset to zero in a SAS macro?
killtest Q78 79 80Help: an I/O ERROR occured
请教SAS advanced 真题中最后一道题sas macro 问题请教。。
adv 63 的第63题question about using sas macro variable and do loop
刚才的sas programmer面试问题请教sas adv的题
sas macro 问题,Stupid SAS programming style is driving me crazy....
相关话题的讨论汇总
话题: macro话题: data话题: do话题: some话题: your
进入Statistics版参与讨论
1 (共1页)
D******n
发帖数: 2836
1
封装的很好的,只需要
%include '....dashagenmacro.sas';
%do_the_work(data=_your_data);
居然有人不会用,问怎么在data step里面include?
output data是啥?这帮人习惯了开膛式的“抄用”别人的code。
服了。
A*******s
发帖数: 3942
2
i don't know how to define a good macro now...
i used to write macros very comprehensively.
then i found out people always have different, special, ad-hoc needs.
now i am trying to write macros as small and simple as possible

【在 D******n 的大作中提到】
: 封装的很好的,只需要
: %include '....dashagenmacro.sas';
: %do_the_work(data=_your_data);
: 居然有人不会用,问怎么在data step里面include?
: output data是啥?这帮人习惯了开膛式的“抄用”别人的code。
: 服了。

c*****1
发帖数: 131
3
"output data是啥?" is a reasonable question.I usually do not put the
results in the same dataset I input.

【在 D******n 的大作中提到】
: 封装的很好的,只需要
: %include '....dashagenmacro.sas';
: %do_the_work(data=_your_data);
: 居然有人不会用,问怎么在data step里面include?
: output data是啥?这帮人习惯了开膛式的“抄用”别人的code。
: 服了。

D******n
发帖数: 2836
4
Well, a good function/subroutine/macro in general programming philosophy
must be well encapsulated and structured.
I was not talking about complexity in my original post. The function/
subroutine/macro should never be too complicated. A simple indicator is the
length of the code. I am for writing simple and small macros(although your
problem may require you to write a lot of sub-macros which will be called by
one main macro).
However i was talking about encapsulation. Its a bad idea that your code
will be totally open to users and they can modify it(if there are so many ad
hoc contingencies, you probably should write a more generic one, and let
them do the ad hoc things outside the macro).
Pertaining to my post, this purpose of the macro is simple(although the
algorithm is not), it is to append a score. So there will be no ad hoc
usages. People are just too used to the ad hoc way of using other ppl's
codes.

【在 A*******s 的大作中提到】
: i don't know how to define a good macro now...
: i used to write macros very comprehensively.
: then i found out people always have different, special, ad-hoc needs.
: now i am trying to write macros as small and simple as possible

D******n
发帖数: 2836
5
For some situations,it is better(maybe safer) to have a output data set. But
for efficiency, you might wanna just append it to your old data set. (it
depends on the purpose of the macro, for example).
Actually I was also thinking what was the best way to do this.
here my macro is to append a score on a data set by my algorithm. there are
two ways to do it.
1)
data temp;
set big;
keep A B C D some_other_vars ...;
run;
%do_the_magic(data=temp);
2)
%do_the_magic;
data &out;
set &data;
keep A B C D;
.....
run;
%mend;
%do_the_magic(data=big,out=small);
I am using 1) and your might be talking about 2). I think 1) is more
flexible, because u can change the keep list outside the macro.

【在 c*****1 的大作中提到】
: "output data是啥?" is a reasonable question.I usually do not put the
: results in the same dataset I input.

c*****1
发帖数: 131
6
what I want to do is:
data temp;
set big;
keep A B C D some_other_vars ...;
run;
%do_the_magic;
data &out;
set &data;
keep A B C D;
.....
run;
%mend;
%do_the_magic(data=big,out=small);
In my opinion, if your macro is given to others to use and you do not expect
time-costing I/O operations caused by huge datasets, simplicity and
readable is much important than the efficiency. 1) does not save much time on small/mid-sized datasets. Also, if the dateset is really huge, the I/O time to generate a new output file can be ignored if your algorithm in the macro is kind of complicated.
Furthermore, do not expect the users are the same clever as you when you write the codes. Some of them are really stupid and you have to explain everything they can not understand. So writing code as simply as you can actually save your time.

But
are

【在 D******n 的大作中提到】
: For some situations,it is better(maybe safer) to have a output data set. But
: for efficiency, you might wanna just append it to your old data set. (it
: depends on the purpose of the macro, for example).
: Actually I was also thinking what was the best way to do this.
: here my macro is to append a score on a data set by my algorithm. there are
: two ways to do it.
: 1)
: data temp;
: set big;
: keep A B C D some_other_vars ...;

D******n
发帖数: 2836
7
well this way will drop all the some_other_vars which are necessary for
subsequent analysis(different users will have different some_other_vars but
A B C D are the same, because they are for the scoring).
1) and 2) are not about which way is simpler, they are pretty much the same
in terms of complexity. What is difference is how to handle the output, on
the file or generate a new file.

【在 c*****1 的大作中提到】
: what I want to do is:
: data temp;
: set big;
: keep A B C D some_other_vars ...;
: run;
: %do_the_magic;
: data &out;
: set &data;
: keep A B C D;
: .....

P****D
发帖数: 11146
8
那说明你写的还不够comprehensive……

【在 A*******s 的大作中提到】
: i don't know how to define a good macro now...
: i used to write macros very comprehensively.
: then i found out people always have different, special, ad-hoc needs.
: now i am trying to write macros as small and simple as possible

A*******s
发帖数: 3942
9
my limited experience is always to generate a new file (a temporary one by
default, or permanent one specified by users). if they wanna merge the two,
do it on ur own plz.
it seems not convenient to macro users but it's convenient to the author.
Otherwise u will hear some complaints like "why ur macro overwrited my data!
!!" , sooner or later!
I used to write very detailed instruction for my macros, but some ppl just
never read it.

but
same

【在 D******n 的大作中提到】
: well this way will drop all the some_other_vars which are necessary for
: subsequent analysis(different users will have different some_other_vars but
: A B C D are the same, because they are for the scoring).
: 1) and 2) are not about which way is simpler, they are pretty much the same
: in terms of complexity. What is difference is how to handle the output, on
: the file or generate a new file.

d********i
发帖数: 76
10
Your macro sucks.
Dan
1 (共1页)
进入Statistics版参与讨论
相关主题
Stupid SAS programming style is driving me crazy....请教SAS advanced 真题中最后一道题
Need advice on SAS macro debuggingadv 63 的第63题
请教如何写这个sas代码?刚才的sas programmer面试问题
[SAS]怎么快捷地删除Macro 里创建的临时dataset和macro variabsas macro 问题,
一个SAS Macro和Append的问题,救助!help. sas macro
如何添加时间变量My $0.02 on SAS debugging in Linux environment.
help need for SAS macroHow to set initial dataset to zero in a SAS macro?
killtest Q78 79 80Help: an I/O ERROR occured
相关话题的讨论汇总
话题: macro话题: data话题: do话题: some话题: your