DATA Step, Macro, Functions and more

need help on a macro program (syntax error)

Accepted Solution Solved
Reply
Super Contributor
Posts: 318
Accepted Solution

need help on a macro program (syntax error)

%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


Accepted Solutions
Solution
‎07-26-2016 11:17 AM
Super User
Posts: 19,768

Re: need help on a macro program (syntax error)

Posted in reply to fengyuwuzu

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


All Replies
Solution
‎07-26-2016 11:17 AM
Super User
Posts: 19,768

Re: need help on a macro program (syntax error)

Posted in reply to fengyuwuzu

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;
Super Contributor
Posts: 318

Re: need help on a macro program (syntax error)

Yes, thanks.
Super Contributor
Posts: 318

Re: need help on a macro program (syntax error)

Posted in reply to fengyuwuzu

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

 

Super User
Posts: 19,768

Re: need help on a macro program (syntax error)

[ Edited ]
Posted in reply to fengyuwuzu

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;
Super Contributor
Posts: 318

Re: need help on a macro program (syntax error)

Thank you so much! This is much better!
☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 266 views
  • 0 likes
  • 2 in conversation