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