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

Thanks. Yes, it is what I want. But I run you code. I did not get the value, wondering whether my computer has problem. 

 

8837 %macro pctvar(ds, var, note);
8838 proc univariate data=&ds. noprint;
8839 var &var.;
8840 output pctlpre=&note._p_ pctlpts= 5 to 95 by 5 out=a;
8841 run;
8842 data _null_;
8843 set a;
8844 array &note._p_ &note._p_:;
8845 do i=1 to dim(&note._p_);
8846 call symputx(vname(&note._p_(i)),&note._p_(i));
8847 end;
8848 run;
8849 %put p_5=&&&note._p_5 p_50=&&&note._p_50 p_95=&&&note._p_95;
8850 %mend;
8851
8852 %pctvar(sashelp.cars, horsepower, hp)
MLOGIC(PCTVAR): Beginning execution.
MLOGIC(PCTVAR): Parameter DS has value sashelp.cars
MLOGIC(PCTVAR): Parameter VAR has value horsepower
MLOGIC(PCTVAR): Parameter NOTE has value hp
MPRINT(PCTVAR): proc univariate data=sashelp.cars noprint;
MPRINT(PCTVAR): var horsepower;
MPRINT(PCTVAR): output pctlpre=hp_p_ pctlpts= 5 to 95 by 5 out=a;
MPRINT(PCTVAR): run;

NOTE: The data set WORK.A has 1 observations and 19 variables.
NOTE: PROCEDURE UNIVARIATE used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds


MPRINT(PCTVAR): data _null_;
MPRINT(PCTVAR): set a;
MPRINT(PCTVAR): array hp_p_ hp_p_:;
MPRINT(PCTVAR): do i=1 to dim(hp_p_);
MPRINT(PCTVAR): call symputx(vname(hp_p_(i)),hp_p_(i));
MPRINT(PCTVAR): end;
MPRINT(PCTVAR): run;

NOTE: There were 1 observations read from the data set WORK.A.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.01 seconds


MLOGIC(PCTVAR): %PUT p_5=&&&note._p_5 p_50=&&&note._p_50 p_95=&&&note._p_95
p_5=&&hp_p_5 p_50=&&hp_p_50 p_95=&&hp_p_95
MLOGIC(PCTVAR): Ending execution.

 

Reeza
Super User

I posted working code. If that doesn't work for you post your full log and the code.
Otherwise go through it line by line and compare and ensure they're exactly the same - they're not.
If you want to make changes for whatever reason, do them one at a time AFTER you've verified the code I posted works as posted.

 


@hellohere wrote:

Thanks. Yes, it is what I want. But I run you code. I did not get the value, wondering whether my computer has problem. 

 

8837 %macro pctvar(ds, var, note);
8838 proc univariate data=&ds. noprint;
8839 var &var.;
8840 output pctlpre=&note._p_ pctlpts= 5 to 95 by 5 out=a;
8841 run;
8842 data _null_;
8843 set a;
8844 array &note._p_ &note._p_:;
8845 do i=1 to dim(&note._p_);
8846 call symputx(vname(&note._p_(i)),&note._p_(i));
8847 end;
8848 run;
8849 %put p_5=&&&note._p_5 p_50=&&&note._p_50 p_95=&&&note._p_95;
8850 %mend;
8851
8852 %pctvar(sashelp.cars, horsepower, hp)
MLOGIC(PCTVAR): Beginning execution.
MLOGIC(PCTVAR): Parameter DS has value sashelp.cars
MLOGIC(PCTVAR): Parameter VAR has value horsepower
MLOGIC(PCTVAR): Parameter NOTE has value hp
MPRINT(PCTVAR): proc univariate data=sashelp.cars noprint;
MPRINT(PCTVAR): var horsepower;
MPRINT(PCTVAR): output pctlpre=hp_p_ pctlpts= 5 to 95 by 5 out=a;
MPRINT(PCTVAR): run;

NOTE: The data set WORK.A has 1 observations and 19 variables.
NOTE: PROCEDURE UNIVARIATE used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds


MPRINT(PCTVAR): data _null_;
MPRINT(PCTVAR): set a;
MPRINT(PCTVAR): array hp_p_ hp_p_:;
MPRINT(PCTVAR): do i=1 to dim(hp_p_);
MPRINT(PCTVAR): call symputx(vname(hp_p_(i)),hp_p_(i));
MPRINT(PCTVAR): end;
MPRINT(PCTVAR): run;

NOTE: There were 1 observations read from the data set WORK.A.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.01 seconds


MLOGIC(PCTVAR): %PUT p_5=&&&note._p_5 p_50=&&&note._p_50 p_95=&&&note._p_95
p_5=&&hp_p_5 p_50=&&hp_p_50 p_95=&&hp_p_95
MLOGIC(PCTVAR): Ending execution.

 





hellohere
Pyrite | Level 9

Not Sure what is going on?!

 

0) How to a macro variable with another macro variable in it?! 

1) Why cannot delete the macro variable(below)? Is my computer having problem?!

GLOBAL P_VOL_B_10 867976
GLOBAL P_VOL_B_15 1205259
GLOBAL P_VOL_B_20 1683118
GLOBAL P_VOL_B_25 2128543
GLOBAL P_VOL_B_30 2660988
GLOBAL P_VOL_B_35 2895309
GLOBAL P_VOL_B_40 3496028
GLOBAL P_VOL_B_45 4244589
GLOBAL P_VOL_B_5 582102
GLOBAL P_VOL_B_50 4632714
GLOBAL P_VOL_B_55 5190511
GLOBAL P_VOL_B_60 6235967
GLOBAL P_VOL_B_65 7352003
GLOBAL P_VOL_B_70 8194236
GLOBAL P_VOL_B_75 10235694
GLOBAL P_VOL_B_80 14296730
GLOBAL P_VOL_B_85 17937992
GLOBAL P_VOL_B_90 23802025
GLOBAL P_VOL_B_95 43347092
GLOBAL START_DT_I 31
GLOBAL TS 1100
WARNING: Attempt to delete macro variable P_VOL_B_10 failed. Variable not found.
8709 %SYMDEL p_vol_B_10;
WARNING: Attempt to delete macro variable P_VOL_B_10 failed. Variable not found.
8710 %SYMDEL P_VOL_B_10;
WARNING: Attempt to delete macro variable P_VOL_B_50 failed. Variable not found.
8711 %SYMDEL P_VOL_B_50;

ballardw
Super User

It appears that you deleted the variable and then attempt to delete it three more times. The 'not found' means the variable does not exist in the scope where you are are attempting the %symdel.

 

 

0) How to a macro variable with another macro variable in it?!

Provide a completely worked example of what this is supposed to mean. Start with some values, describe the rules and then show the final result.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 19 replies
  • 3382 views
  • 2 likes
  • 5 in conversation