DATA Step, Macro, Functions and more

Use macro to convert multiple STATA files to SAS files

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 98
Accepted Solution

Use macro to convert multiple STATA files to SAS files

Hi all,

I've asked a similar question previously at . But the answer does not seem to address my current case.

I have 10 STATA files which I need to convert to SAS files. Their files names are like "us_ny_YEAR_core.dta"; here, "YEAR" stands for each specific year from 2001 to 2010. As I tried to do the following macro to convert the files, it does not work.

%macro convert_data();

%do i=2001 %to 2010;

proc import out=ny&i datafile="C:\data\us_ny_&i_core.dta";run;

%end;

%mend;

%convert_data();

run;

Anyone has any suggestion? Thanks so much!

Lizi


Accepted Solutions
Solution
‎02-10-2015 11:00 AM
Super User
Posts: 11,343

Re: Use macro to convert multiple STATA files to SAS files

"C:\data\us_ny_&i_core.dta"

should be

"C:\data\us_ny_&i._core.dta"

the . after the macro variable says to append the following text. As written it is looking for a macro variable named I_core

View solution in original post


All Replies
Solution
‎02-10-2015 11:00 AM
Super User
Posts: 11,343

Re: Use macro to convert multiple STATA files to SAS files

"C:\data\us_ny_&i_core.dta"

should be

"C:\data\us_ny_&i._core.dta"

the . after the macro variable says to append the following text. As written it is looking for a macro variable named I_core

Frequent Contributor
Posts: 98

Re: Use macro to convert multiple STATA files to SAS files

Thanks, Ballard. I see your point.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 281 views
  • 0 likes
  • 2 in conversation