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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.