I have a lot of sas dataset files that starts with "s" followed by some numbers like s1 s7 s13 s32 etc. (I have a lot).
For each files I run a set of codes, save my last result and then restart with with the following dataset file. Normally, when my dataset file numbers are sequential like s1 s2 s3 s4 s5...it is easy to use for instance a %do i=1 %to 120
. But what if I want to do a loop with unequal increments? How can I do this? Like for instance a %do i=1 7 13 32...
. This is quite easy in MATLAB but in SAS I am not too sure how.
%SCAN is your friend here. Take a look at the example code below -
%let nums = 1 2 4 6 13 29 32;
%macro iter();
%let cnt = %sysfunc(countc(&nums," "));
%let cnt = %eval(&cnt + 1);
%put &cnt;
%do i = 1 %to &cnt;
%put I will now process dataset s%scan(&nums,&i," ");
%end;
%mend iter;
%iter()
You can modify the part %put... to write a DATA step.