BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Valeidoscope
Fluorite | Level 6

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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?

Spoiler
Objects= "apple,  bee, church";

How could you change your macro code so it produces that statement?

Spoiler
Objects= "&List.";

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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?

Spoiler
Objects= "apple,  bee, church";

How could you change your macro code so it produces that statement?

Spoiler
Objects= "&List.";
Valeidoscope
Fluorite | Level 6

That worked, thank you!

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 531 views
  • 1 like
  • 2 in conversation