if &&&who resolves to 17 then why is William 23 excluded from the output results. Can someone please explain?
options mprint symbolgen;
data kids;
input name $ age;
call symput(name, age);
datalines;
Cora 21
Emma 15
Hannah 17
William 23
;
%let who = Hannah;
proc print data=kids;
title "Kids older than &who";
where age > &&&who;
run;
It is included when I run it. Note: Use call symputX() to avoid the spaces in the macro variable values.
307 proc print data=kids;
SYMBOLGEN: Macro variable WHO resolves to Hannah
308 title "Kids older than &who";
309 where age
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable WHO resolves to Hannah
SYMBOLGEN: Macro variable HANNAH resolves to 17
309! > &&&who;
310 run;
NOTE: There were 2 observations read from the data set WORK.KIDS.
WHERE age>17;
It is included when I run it. Note: Use call symputX() to avoid the spaces in the macro variable values.
307 proc print data=kids;
SYMBOLGEN: Macro variable WHO resolves to Hannah
308 title "Kids older than &who";
309 where age
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable WHO resolves to Hannah
SYMBOLGEN: Macro variable HANNAH resolves to 17
309! > &&&who;
310 run;
NOTE: There were 2 observations read from the data set WORK.KIDS.
WHERE age>17;
but does not the macro processor ignores spaces before the 1st non-blank character and everything after the ";" in the value to be assigned to a macro variable?
Yes, but CALL SYMPUT() does not perform a %LET.
In your particular code
age > &&&who
the leading spaces are not a problem, but in other cases they can be. For example if comparing the value in a quoted string.
"17" = "&&&who"
Then the leading spaces in the value of the macro variable HANNAH would cause that condition to be false as "17" does not equal " 17".
i see. A very good point.
Thanks Tom
Its not from mine. You must have some other mistake in your code.
Kids older than Hannah | 5 | |
09:20 Monday, November 18, 2013 |
Obs | name | age |
1 | Cora | 21 | |
4 | William | 23 |
I would expect no problems from the code the way you posted it, but there would be a problem if you had a longer name such as Bartholomew. If you can't post the exact code that you ran, it might help to add this statement after the first DATA step: %put _user_;
Good luck.
thanks guys,
i actually had to restart my SAS to get the results you all got.Weird...
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.