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!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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