BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fengyuwuzu
Pyrite | Level 9
%macro percent(var=);
proc univariate data=simple ;
var &var ;
output out=percent pctlpre=P pctlpts=90 95 98 99;
run;

Proc sql;
   create table &var_flag as
   select a.*, 
	 (a.&var ge b.P90) as P90_flag,
     (a.&var ge b.P95) as P95_flag,
	 (a.&var ge b.P98) as P98_flag,
	 (a.&var ge b.P99) as P99_flag
   from simple as a,  percent as b;
quit;

data &var_p99 &var_p98 &var_p95 &var_p90;
set &var_flag;
if P99_flag =1 then output &var_p99;
if P98_flag =1 then output &var_p98;
if P95_flag =1 then output &var_p95;
if P90_flag =1 then output &var_p90;
run;
%mend percent;

when I ran it, I got:

NOTE: Line generated by the invoked macro "PERCENT".
1        create table &var_flag as    select a.*, (a.&var ge b.P90) as P90_flag,      (a.&var ge b.P95)

-

22

200
1  ! as P95_flag,      (a.&var ge b.P98) as P98_flag,
WARNING: Apparent symbolic reference VAR_FLAG not resolved.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string.

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds

WARNING: Apparent symbolic reference VAR_P99 not resolved.

 

can anyone tell me where is wrong? Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

The error is:

WARNING: Apparent symbolic reference VAR_P99 not resolved.

 

SAS is looking for a macro variable called VAR_P99

 

You need to end your macro variable with a period when using it as part of a name so SAS knows where the macro variable ends.

 

data &var._p99 &var._p98 &var._p95 &var._p90;

View solution in original post

5 REPLIES 5
Reeza
Super User

The error is:

WARNING: Apparent symbolic reference VAR_P99 not resolved.

 

SAS is looking for a macro variable called VAR_P99

 

You need to end your macro variable with a period when using it as part of a name so SAS knows where the macro variable ends.

 

data &var._p99 &var._p98 &var._p95 &var._p90;
fengyuwuzu
Pyrite | Level 9
Yes, thanks.
fengyuwuzu
Pyrite | Level 9

it seems &var cannot be in the beginning of data set names.

when I changed &var_flag to flag_&var, and also &var_p99 &var_p98 etc

the code works

 

Reeza
Super User

You could merge that SQL and data step into one step...

 

 

data &var._p99 &var._p98 &var._p95 &var._p90;

if _n_=1 then set percent;

set simple;

p90_flag = &var ge P90;

if p90_flag=1 then output &var._p99;

etc...


run;
fengyuwuzu
Pyrite | Level 9
Thank you so much! This is much better!

sas-innovate-2024.png

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.

 

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
  • 5 replies
  • 795 views
  • 0 likes
  • 2 in conversation