Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

export - running sas program for multiple parameters in loop

Very new to sas, need to perform export procedure for many datasets called data1, data2, data3 ... data10. Is there a way to operationalize this? I've tried the following without success

LIBNAME input '/home/.../input';

LIBNAME output '/home/.../output';

%macro anynumber(number);

proc export data=input.data&number file="/home/.../output/data&number..dta" dbms=dta replace;
run;    
    
%mend;


do i = 1 to 10;

   %anynumber(i)

end;

run;
question from:https://stackoverflow.com/questions/65852014/running-sas-program-for-multiple-parameters-in-loop

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

CALL EXECUTE is the recommended option but a macro loop is also a good option here. You could loop it within the same macro as well. All options are illustrated below.

Usually when I see this type of coding though, my first thought is that someone isn't familiar with BY group processing.

data demo;
   do i=1 to 10;
        *make sure this string matches macro call;
        str = catt('%anynumber(', i, ');');
        *write records to log to check;
        put str;
        call execute(str);
   end;
run;

Another option is a macro loop itself.

%macro loop_export(numLoops=10);

  %do i=1 %to &numLoops;
      %anywhere(&i);
   %end;

%mend;

%loop_export(numLoops=10);

Putting them together:

%macro anynumber(number);
%do i=1 %to &number;
    proc export data=input.data&number file="/home/.../output/data&i..dta" dbms=dta 
   replace;
   run;  
 %end;  
    
%mend;

*will export all 10;
%anyNumber(10);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...