playmore 发表于 2012-12-12 15:57 
需要考虑
因为我想写个宏,用于处理各式的表格
Hi Playmore,
I know the posting is back to last year. However I try to create a macro as an exercise.
If you have time, please go through it, and let me know any concerns. Thanks in advance.
data have;
input ByFactors $ Name $ MEAN STD;
datalines;
2009 A 23 41
2009 B 45 37
2010 A 27 53
2010 B 12 90
2012 C 23 35
2012 D 12 23
2011 A 23 45
;
run;
%MACRO createwant;
/*get the name with no duplicate*/
proc sort data=have out=have1 (keep=name) nodupkey;
by name;
run;
/*put all the name into a string*/
data _null_;
set have1 end=last;
length test $200;
retain test;
test=catx(' ',test,name);
if last then call symputx('mytest',test);
run;
/*Create the final dataset*/
data want;
%let i=1;
merge
%do %until(not %length(%scan(&mytest,&i)));
have(where=(name="%scan(&mytest,&i)") rename=(mean=mean_%scan(&mytest,&i) std=std_%scan(&mytest,&i)))
%let i=%eval(&i+1);
%end;
;
by byfactors;
drop name;
run;
/*Delete the temp sataset*/
proc datasets library=work;
delete have1;
run;
quit;
%MEND createwant;
%createwant