## macro problem

Solved
Super Contributor
Posts: 464

# macro problem

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;

Accepted Solutions
Solution
‎11-18-2013 01:22 PM
Super User
Posts: 8,093

## Re: macro problem

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;

All Replies
Solution
‎11-18-2013 01:22 PM
Super User
Posts: 8,093

## Re: macro problem

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;

Super Contributor
Posts: 464

## Re: macro problem

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?

Super User
Posts: 8,093

## Re: macro problem

Yes, but CALL SYMPUT() does not perform a %LET.

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

Super Contributor
Posts: 464

## Re: macro problem

i see. A very good point.

Thanks Tom

Super User
Posts: 23,709

## Re: macro problem

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
Super User
Posts: 6,769

## Re: macro problem

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.

Super Contributor
Posts: 464

## Re: macro problem

thanks guys,

i actually had to restart my SAS to get the results you all got.Weird...

🔒 This topic is solved and locked.