Pergunta

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!

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top