I am trying to put the words from the List macro into the Objects column in specific scenarios.
Here's an excerpt of the code:
%let A= 16;
%let List= %str(apple, bee, church)
%put List= &List.;
OPTIONS MPRINT SYMBOLGEN MLOGIC;
data want; set have;
if C= "Yes" then
do;
Count = &A.;
Objects= &List.;
end;
run;
proc print data= want (obs=10); run;
SYMBOLGEN says that the macro resolves correctly but I get this error when I run my code and the Objects column is not populated:
NOTE: Line generated by the macro variable "List".
1 apple, bee, church
-
22
-
76
ERROR 22-322: Syntax error, expecting one of the following: (, [, {
The under scores are on the comma after the first word.
Any insight or possible solutions are appreciated
You need to use the macro language to generate valid SAS language statements.
You set the macro LIST to the string
apple, bee, church
And then you used it this way:
Objects= &List.;
Which means you tried to run this SAS statement:
Objects= apple, bee, church;
And that is NOT a valid SAS statement.
What would be a valid SAS statement?
Objects= "apple, bee, church";
How could you change your macro code so it produces that statement?
Objects= "&List.";
You need to use the macro language to generate valid SAS language statements.
You set the macro LIST to the string
apple, bee, church
And then you used it this way:
Objects= &List.;
Which means you tried to run this SAS statement:
Objects= apple, bee, church;
And that is NOT a valid SAS statement.
What would be a valid SAS statement?
Objects= "apple, bee, church";
How could you change your macro code so it produces that statement?
Objects= "&List.";
That worked, thank you!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.