DATA Step, Macro, Functions and more

Call Symput

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Call Symput

I am not able to get why the following code is not working properly. Can anybody pls help.

%let x = dav;
data xx;

if &x = div then call symput('holdid', 'div' );
else if &x = dav then call symput('holdid', 'dav');

run;


%put x= &x;
%put holdid= &holdid

Why the result is coming as follows and what might be alternative solution?

SYMBOLGEN:  Macro variable X resolves to dav

713

714

715  %put x= &x;

x= dav

716  %put holdid= &holdid;

SYMBOLGEN:  Macro variable HOLDID resolves to div

holdid= div


Accepted Solutions
Solution
‎11-27-2012 11:21 AM
Super User
Posts: 5,500

Re: Call Symput

Posted in reply to Sarojkumar

Certainly LinusH is correct in that you could always use:

%let holdid = &x;

Probably your question is a simplification of a more complicated scenario.  The reason you are getting your results goes back to this DATA step statement:

if dav = div then call symput (.....);

That's the code that SAS sees, after macro language finishes resolving &X.  In a DATA step, DAV and DIV will both be numeric variables with a missing value, so the comparison will be true.  One way to get around it, if  you really need to do that for a more complex scenario, is this:

if "&x" = "div" then call symput (.....);

That way, after resolving &X, SAS compares:

if "dav" = "div" then call symput (.....);

Good luck.

View solution in original post


All Replies
Super User
Posts: 5,426

Re: Call Symput

Posted in reply to Sarojkumar

What are you trying to do?

This piece of code doesn't do anything...?

If you are trying to  assign the macro variable holid depending on the value of X, the you should use pure macro logic, no use for a data step if this is the case.

Data never sleeps
Occasional Contributor
Posts: 14

Re: Call Symput

Ok, then can you tell me why I am not getting the expected result.

data xx;
x=dav;

if x = div then call symput('holdid', 'div' );
else if x = dav then call symput('holdid', 'dav');

run;

%put holdid= &holdid;

I am getting the following result:

 

SYMBOLGEN: Macro variable HOLDID resolves to div

807

808

809 %put holdid= &holdid;

holdid= div

Super User
Posts: 5,500

Re: Call Symput

Posted in reply to Sarojkumar

But you are getting the expected result.

X is a numeric variable, with a missing value.

DAV is a numeric variable, with a missing value.

DIV is a numeric variable with a missing value.

So this comparison is true:

if x = div then call symput ....;

Therefore, the ELSE statement is ignored.


Occasional Contributor
Posts: 14

Re: Call Symput

Posted in reply to Astounding

Thanks Astounding. I mixed up the datastep processing concepts with macro processing concepts. Smiley Happy

Solution
‎11-27-2012 11:21 AM
Super User
Posts: 5,500

Re: Call Symput

Posted in reply to Sarojkumar

Certainly LinusH is correct in that you could always use:

%let holdid = &x;

Probably your question is a simplification of a more complicated scenario.  The reason you are getting your results goes back to this DATA step statement:

if dav = div then call symput (.....);

That's the code that SAS sees, after macro language finishes resolving &X.  In a DATA step, DAV and DIV will both be numeric variables with a missing value, so the comparison will be true.  One way to get around it, if  you really need to do that for a more complex scenario, is this:

if "&x" = "div" then call symput (.....);

That way, after resolving &X, SAS compares:

if "dav" = "div" then call symput (.....);

Good luck.

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 290 views
  • 0 likes
  • 3 in conversation