I am trying to write a program involving a macro, and it fails at a very initial stage.
Code:
options symbolgen mprint mlogic;
%let lib=aa_temp1;
%let dsname=Party_Details;
%macro test;
data test11;
set &lib..&dsname.;
run;
%mend;
%test();
Error when executed:
SYMBOLGEN: Macro variable lib resolves to aa_temp1
SYMBOLGEN; Macro variable dsname resolves to Party_Details
data test11; set &lib..&dsname.; run;
____
180
ERROR 180-322: Statement is not valid or used out of proper order.
MPRIINT(TEST): Set aa_temp1.Party_Details;
I have tried the dsname in Set as &dsname as well as &dsname. , and there is the same error. Tried searching for the error, and still not sure why this simple line generates error. What is that I am missing?
Your code as shown works fine.
%let lib=sashelp;
%let dsname=class;
%macro test;
data test11;
set &lib..&dsname.;
run;
%mend;
%test;MLOGIC(TEST): Beginning execution.
MPRINT(TEST): data test11;
SYMBOLGEN: Macro variable LIB resolves to sashelp
SYMBOLGEN: Macro variable DSNAME resolves to class
MPRINT(TEST): set sashelp.class;
MPRINT(TEST): run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.TEST11 has 19 observations and 5 variables.
NOTE: DATA statement used:
real time 0.01 seconds
cpu time 0.00 seconds
MLOGIC(TEST): Ending execution.I suspect you are doing something different and your macro values are quoted. Try using the %unquote() function.
Yes, please double-check that the code you posted is the same as the code you submitted.
Note that your macro call %test() ; has parentheses, even though the macro does not have any parameters. This will create the error message you get, though not near the SET statement. So @ChrisNZ's suggestion about possible macro quoting in your real code is a good one.
WHen I run your code as is, I get below log:
26 %test();
MLOGIC(TEST): Beginning execution.
MPRINT(TEST): data test11;
SYMBOLGEN: Macro variable LIB resolves to aa_temp1
SYMBOLGEN: Macro variable DSNAME resolves to Party_Details
MPRINT(TEST): set aa_temp1.Party_Details;
MPRINT(TEST): run;
NOTE: There were 1 observations read from the data set AA_TEMP1.PARTY_DETAILS.
NOTE: The data set WORK.TEST11 has 1 observations and 1 variables.
MLOGIC(TEST): Ending execution.
180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN
where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.