data a;
input sc $ pt map;
cards;
a 1 62
b 3 9
c 2 7
d 1 12
;
run;
%macro na;
proc sql;
select count(*) into :n from a;
select sc into :va separated by ' ' from a;
quit;
%do i=1 %to &n.;
proc sql;
create table a_&va. as
select * from a
where sc=%scan(&va.,&i.);
quit;
%end;
%mend;
%na作者: shiyiming 时间: 2011-5-6 21:00 标题: Re: 请高手指点一下macro程序中的错误,急! [code:2ep5zn1n]%macro na;
proc sql;
select count(*) into :n from a;
select sc into :va separated by ' ' from a;
quit;
%put &va.;
%do i=1 %to &n.;
proc sql;
create table a_%scan(&va.,&i.) as
select * from a
where sc="%scan(&va.,&i.)";
quit;
%end;
%mend;
%na[/code:2ep5zn1n]
The following code may be shorter.
[code:2ep5zn1n]proc sort data =a out =b(keep =sc) nodupkey; by sc;
run;
data _null_;
set b;
call execute('data a_'||strip(sc)||'; set a; where sc='||'"'||strip(sc)||'"; run;');
run;[/code:2ep5zn1n]作者: shiyiming 时间: 2011-5-6 22:16 标题: Re: 请高手指点一下macro程序中的错误,急! thanks a lot, that is super nice.
还有个问题:就是怎么再把这些新产生的data (ds_a, ds_b,...)用excel一个一个的sheet自动存在同一个excel文件里,sheet名字就用a,b,c....
谢谢!!!作者: shiyiming 时间: 2011-5-7 01:58 标题: Re: 请高手指点一下macro程序中的错误,急! Many ways work on that. One of fairly simple ways is like the following:
[code:daepyy2p]libname urxls "c:\aa.xls";
proc sort data =a out =b(keep =sc) nodupkey; by sc;
run;
data _null_;
set b;
call execute('data urxls.a_'||strip(sc)||'; set a; where sc='||'"'||strip(sc)||'"; run;');
run;
libname urxls clear;[/code:daepyy2p]