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" ;
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: