%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
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;
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;
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
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.