문제

I am trying to export many files files where the exported filename reflects the iteration of a loop. Using the following code I the exported file is named "history_%i.dta" instead of the desired "history_0.dta", "history_1.dta", "history_2.dta", etc...

%macro exporthistory;
   %do i = 0 %to 9;
      proc export data = a.history&i outfile = "LOCATION/history_%i.dta";
      run;
   %end;
%mend exporthistory;

%exporthistory;

Thanks in advance!

도움이 되었습니까?

해결책

Change history_%i.dta to `history_&i..dta'.

%macro exporthistory;
   %do i = 0 %to 9;
     proc export data = a.history&i outfile = "LOCATION/history_&i..dta";
     run;
   %end;
%mend exporthistory;

%exporthistory;

Ampersand ("&") is the macro variable delimiter, as you correctly use earlier. Also, you need a second period as &i. is the macro variable, and the second period is part of the filename.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top