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" ;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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