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;
You need quotation marks
where three="&test";
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" ;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.