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 | |
|