symputx question

Accepted Solution Solved
Reply
Valued Guide
Posts: 860
Accepted Solution

symputx question

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;


Accepted Solutions
Solution
‎12-07-2014 12:29 AM
Super User
Posts: 19,770

Re: symputx question

Posted in reply to Steelers_In_DC

You need quotation marks

where three="&test";

View solution in original post


All Replies
Solution
‎12-07-2014 12:29 AM
Super User
Posts: 19,770

Re: symputx question

Posted in reply to Steelers_In_DC

You need quotation marks

where three="&test";

Super User
Super User
Posts: 7,039

Re: symputx question

Posted in reply to Steelers_In_DC

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 165 views
  • 3 likes
  • 3 in conversation