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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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