I've only been using SAS for about a year, so there is probably a much more straightforward way to accomplish what I'm trying to do. I'm using a where statement in a datastep. I have the set statement in a do loop so I can concatenate large numbers of files. The only way I know to speed up the process is to use a key variable the way I'm doing it. Is there a better way? Here is a generic example : *creating a dummy set;
data dummyset dummyset1 dummyset2 dummyset3;
length id $7.;
do i=1 to 30000;
id=strip(put(i,$7.));
output dummyset dummyset1 dummyset2 dummyset3;
end;
run;
%macro IDlist(listcount,iteration);
*next several steps create N lists of key variables;
data listID (keep=ID);
n=_n_;
set dummyset nobs=number_of_total_obs;
if number_of_total_obs=1 then do;
call symput('listcount','1');
call symput('iteration','1');
end;
listsize=round(number_of_total_obs/&listcount)*(&iteration);
lastlist=round(number_of_total_obs/&listcount)*((&iteration)-1);
lengthsize=((round(number_of_total_obs/&listcount))*8)+100;
call symput('lengthsize',cats("$",strip(lengthsize),"."));
if lastlist < n <= listsize then output;
run;
%put &lengthsize;
proc sort data=listID;
by id;
*put all key variables on one line in order to concatenate in next step;
proc transpose
data=listID
out=listID
prefix=ID;
var ID;
*create list;
data _null_;
length allIDs allIDs2 &lengthsize;
set listid (keep=id:);
array char_array [*] _character_;
do i = 1 to dim(char_array);
allIDs=catx("','",allIDs,strip(char_array[i]));
end;
allIDs2=cats("'",strip(allIDs),"'");
%global idlist&iteration;
call symput("idlist&iteration",allIDs2);
run;
%mend IDlist;
%macro makelists;
%let a=15;
%do b=1 %to 15;
%IDlist(&a,&b);
%end;
%mend makelists;
%makelists;
%let start=1;
%let stop=3;
*run files;
Data idtest;
set %macro idloop;
%do i=&start %to &stop %by 1;
dummyset&i (keep=id where=(id in (&idlist5,&idlist6)))
%end;
%mend idloop;
%idloop;;
run; Thank you
... View more