BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Steelers_In_DC
Barite | Level 11

I have a very simple example that I cannot get to work and I have no idea why.  The macro variable is recognized in the put statement but not when used to pull the data in a datastep.  Please help.

Thank You,

data data;
infile cards;
input one $ two $ three $;
cards;
0110 Mark 001129
;
run;

data _null_;
set data;
if one = '0110' then call symputx('test',three);
run;

%put &test;

data test;
set data;
where three = &test;
run;

28        
29         %put &test;
001129
30        
31         data test;
32         set data;
33         where three = &test;
ERROR: WHERE clause operator requires compatible variables.
34         run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You need quotation marks

where three="&test";

View solution in original post

2 REPLIES 2
Reeza
Super User

You need quotation marks

where three="&test";

Tom
Super User Tom
Super User

Your macro variable is being created properly, but you are using it to generate invalid SAS syntax.

You wrote

WHERE THREE = 001129 ;

SAS is telling you that THREE is a character variable so you cannot compare it to a number.  In SAS literal strings need to be enclosed in quotes. So this would work:

WHERE THREE = "001129" ;


You will need to use double quote characters so that the macro variable reference will be expanded. 

WHERE THREE = "&test" ;

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
  • 497 views
  • 3 likes
  • 3 in conversation