DATA Step, Macro, Functions and more

Changing Dataset Names using SAS Macros

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

Changing Dataset Names using SAS Macros

I'm fairly new to this Macro things and I would like to have a dataset be named according to a parameter that is set using a "macro"-type paremeter -

 

 

DATA _NULL_;
%LET reportingdt = %str(June2016);
RUN;

proc import datafile="C:\Users\cafarrel\Desktop\\REPORTING_DATA.sav"
out=farrsas.reporting_&reportingdt dbms = sav replace;
run;

 

 

 

whenever I run this I get the following error message:

 

NOTE: The SAS System stopped processing this step because of errors.

26 proc import datafile="C:\Users\cafarrel\Desktop\\REPORTING_DATA.sav"

27 out=farrsas.reporting_&reportingdt. dbms = sav replace;

NOTE: Line generated by the macro variable "REPORTINGDT".

27 farrsas.reporting_June2016

________

22

________

202

ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATAFILE, DATATABLE, DBMS, DEBUG, FILE, OUT, REPLACE, TABLE,

_DEBUG_.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

28 run;

 

 

What am i doing wrong? Smiley Sad

 

 


Accepted Solutions
Solution
‎08-31-2016 10:40 AM
Super User
Posts: 5,500

Re: Changing Dataset Names using SAS Macros

[ Edited ]
Posted in reply to camfarrell25

A likely culprit:  quoting functions such as %STR insert unseen quoting characters.  Usually SAS manages to remove them in time, but perhaps that is not happening here.  Try it this way:

 

%let reportingdt = Jun2016;

 

proc import .........; (no changes required)

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Changing Dataset Names using SAS Macros

Posted in reply to camfarrell25

Look closely at of proc import datafile="C:\Users\cafarrel\Desktop\\REPORTING_DATA.sav"

2 slashes in the file name, and since one looks different when I paste it, the second may not be the character it looked like below.

 

Not that it causes the error but this

DATA _NULL_;
%LET reportingdt = %str(June2016);
RUN;

Only needs to be:

 

%LET reportingdt = %str(June2016);

It will help to post log extracts with errors using the entry box brough up by the "run" icon to preserve formating so we can see

where the underlines are generated.

Solution
‎08-31-2016 10:40 AM
Super User
Posts: 5,500

Re: Changing Dataset Names using SAS Macros

[ Edited ]
Posted in reply to camfarrell25

A likely culprit:  quoting functions such as %STR insert unseen quoting characters.  Usually SAS manages to remove them in time, but perhaps that is not happening here.  Try it this way:

 

%let reportingdt = Jun2016;

 

proc import .........; (no changes required)

New Contributor
Posts: 4

Re: Changing Dataset Names using SAS Macros

Posted in reply to camfarrell25

try setting the macro variable (first three lines of your program) as follows:

 

%let <macro_variable_name> = <macro_variable_argument> ;

 

The datastep data _null_ is ok but irrelevant (%let can be used in open code).

 

The %str() function seems to be the problem: I ran it without that and the code worked.

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 257 views
  • 1 like
  • 4 in conversation