BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

7 REPLIES 7
Tom
Super User Tom
Super User

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;

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

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?

Tom
Super User Tom
Super User

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

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

i see. A very good point.

Thanks Tom

Reeza
Super User

Its not from mine. You must have some other mistake in your code.

     Kids older than Hannah                                5
                                                             09:20 Monday, November 18, 2013

                                 Obsname   age

                                  1 Cora    21
                                  4 William 23
Astounding
PROC Star

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.

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

thanks guys,

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 894 views
  • 0 likes
  • 4 in conversation