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? 😞
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)
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.
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)
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.