I got ERROR msg below.
The macro codes are running fine. I move somewhere a little bit, RUN and got ERROR msg below. Any one can help?
ERROR: An exception has been encountered.
Please contact technical support and provide them with the following traceback information:
The SAS task name is [Submit]
ERROR: Stack overflow detected Submit
Exception occurred at (0521A6D7)
Task Traceback
It has lots of macros. Days ago, it is all fine. Now I run step by step. It says the one below is not fine.
%put "p_5=&¬e._p_5. p_50=&¬e._p_50. p_95=&¬e._p_95.";
The line above does not print the expected values[the macro supposes to assign percentiles to macro variables].
Thanks,
%pctvar(sashelp.cars, horsepower, hp);
%macro pctvar(ds, var, note);
proc univariate data=&ds. noprint;
var &var.;
output pctlpre=¬e._p_ pctlpts= 5 to 95 by 5;
run;
proc print; run;
data _null_;
set;
array ¬e._p_ ¬e._p_:;
do over ¬e._p_;
call symputx(vname(¬e._p_),¬e._p_);
end;
stop;
run;quit;
%put "p_5=&¬e._p_5. p_50=&¬e._p_50. p_95=&¬e._p_95.";
%mend;
Show the result of YOUR code and what you expect the output to be.
You say "The line above does not print the expected values" but have not provided any evidence of that, i.e. the actual output and the expected output.
@hellohere wrote:
It has lots of macros. Days ago, it is all fine. Now I run step by step. It says the one below is not fine.
%put "p_5=&¬e._p_5. p_50=&¬e._p_50. p_95=&¬e._p_95.";
The line above does not print the expected values[the macro supposes to assign percentiles to macro variables].
Thanks,
%pctvar(sashelp.cars, horsepower, hp);
%macro pctvar(ds, var, note);
proc univariate data=&ds. noprint;
var &var.;
output pctlpre=¬e._p_ pctlpts= 5 to 95 by 5;
run;
proc print; run;
data _null_;
set;
array ¬e._p_ ¬e._p_:;
do over ¬e._p_;
call symputx(vname(¬e._p_),¬e._p_);
end;
stop;
run;quit;
%put "p_5=&¬e._p_5. p_50=&¬e._p_50. p_95=&¬e._p_95.";
%mend;
The according percentile in the dataset from SAS
115 | 130 | 140 | 155 | 165 | 172 | 184 | 193 | 200 | 210 | 215 | 224 | 230 | 240 | 255 | 275 | 295 | 302 | 340 |
%macro pctvar(ds, var, note);
proc univariate data=&ds. noprint;
var &var.;
output out=a pctlpre=¬e._p_ pctlpts= 5 to 95 by 5;
run;
data _null_;
set a;
array ¬e._p_ ¬e._p_:;
do over ¬e._p_;
call symputx(vname(¬e._p_), ¬e._p_, 'g');
end;
run;
proc sql;
drop table a;
quit;
%put "p_5=&&¬e._p_5. p_50=&&¬e._p_50. p_95=&&¬e._p_95.";
%mend;
%pctvar(sashelp.cars, horsepower, hp);
%put &hp_p_5.;
%put &hp_p_50;
Log:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 68 69 70 options mprint symbolgen; 71 72 %macro pctvar(ds, var, note); 73 proc univariate data=&ds. noprint; 74 var &var.; 75 output out=a pctlpre=¬e._p_ pctlpts= 5 to 95 by 5; 76 run; 77 78 data _null_; 79 set a; 80 array ¬e._p_ ¬e._p_:; 81 do over ¬e._p_; 82 call symputx(vname(¬e._p_), ¬e._p_, 'g'); 83 end; 84 run; 85 86 proc sql; 87 drop table a; 88 quit; 89 90 %put "p_5=&&¬e._p_5. p_50=&&¬e._p_50. p_95=&&¬e._p_95."; 91 %mend; 92 93 %pctvar(sashelp.cars, horsepower, hp); SYMBOLGEN: Macro variable DS resolves to sashelp.cars MPRINT(PCTVAR): proc univariate data=sashelp.cars noprint; SYMBOLGEN: Macro variable VAR resolves to horsepower MPRINT(PCTVAR): var horsepower; SYMBOLGEN: Macro variable NOTE resolves to hp MPRINT(PCTVAR): output out=a pctlpre=hp_p_ pctlpts= 5 to 95 by 5; 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.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 634.75k OS Memory 26020.00k Timestamp 01/18/2022 06:10:28 PM Step Count 59 Switch Count 2 Page Faults 0 Page Reclaims 102 Page Swaps 0 Voluntary Context Switches 10 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 264 MPRINT(PCTVAR): data _null_; MPRINT(PCTVAR): set a; SYMBOLGEN: Macro variable NOTE resolves to hp SYMBOLGEN: Macro variable NOTE resolves to hp MPRINT(PCTVAR): array hp_p_ hp_p_:; SYMBOLGEN: Macro variable NOTE resolves to hp MPRINT(PCTVAR): do over hp_p_; SYMBOLGEN: Macro variable NOTE resolves to hp SYMBOLGEN: Macro variable NOTE resolves to hp MPRINT(PCTVAR): call symputx(vname(hp_p_), hp_p_, 'g'); 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.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 647.62k OS Memory 26276.00k Timestamp 01/18/2022 06:10:28 PM Step Count 60 Switch Count 0 Page Faults 0 Page Reclaims 100 Page Swaps 0 Voluntary Context Switches 0 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 8 MPRINT(PCTVAR): proc sql; MPRINT(PCTVAR): drop table a; NOTE: Table WORK.A has been dropped. MPRINT(PCTVAR): quit; NOTE: PROCEDURE SQL used (Total process time): real time 0.00 seconds user cpu time 0.00 seconds system cpu time 0.00 seconds memory 46.25k OS Memory 26016.00k Timestamp 01/18/2022 06:10:28 PM Step Count 61 Switch Count 2 Page Faults 0 Page Reclaims 14 Page Swaps 0 Voluntary Context Switches 9 Involuntary Context Switches 0 Block Input Operations 0 Block Output Operations 0 SYMBOLGEN: && resolves to &. SYMBOLGEN: Macro variable NOTE resolves to hp SYMBOLGEN: Macro variable HP_P_5 resolves to 115 SYMBOLGEN: && resolves to &. SYMBOLGEN: Macro variable NOTE resolves to hp SYMBOLGEN: Macro variable HP_P_50 resolves to 210 SYMBOLGEN: && resolves to &. SYMBOLGEN: Macro variable NOTE resolves to hp SYMBOLGEN: Macro variable HP_P_95 resolves to 340 "p_5=115 p_50=210 p_95=340" 94 95 %put &hp_p_5.; SYMBOLGEN: Macro variable HP_P_5 resolves to 115 115 96 %put &hp_p_50.; SYMBOLGEN: Macro variable HP_P_50 resolves to 210 210 97 98 99 100 101 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; SYMBOLGEN: Macro variable GRAPHTERM resolves to GOPTIONS NOACCESSIBLE; 111
@hellohere wrote:
It has lots of macros. Days ago, it is all fine. Now I run step by step. It says the one below is not fine.
%put "p_5=&¬e._p_5. p_50=&¬e._p_50. p_95=&¬e._p_95.";
The line above does not print the expected values[the macro supposes to assign percentiles to macro variables].
Thanks,
%pctvar(sashelp.cars, horsepower, hp);
%macro pctvar(ds, var, note);
proc univariate data=&ds. noprint;
var &var.;
output pctlpre=¬e._p_ pctlpts= 5 to 95 by 5;
run;
proc print; run;
data _null_;
set;
array ¬e._p_ ¬e._p_:;
do over ¬e._p_;
call symputx(vname(¬e._p_),¬e._p_);
end;
stop;
run;quit;
%put "p_5=&¬e._p_5. p_50=&¬e._p_50. p_95=&¬e._p_95.";
%mend;
@hellohere said:
I assign the percentile values to macro variables and use them down the stream.
This is not an answer to my question. Yes, I knew that you were going to use the macro variables, otherwise you wouldn't put all this work into creating them. I want to know how you are going to use them ... are you going to use them for outlier detection, or reporting, or plotting or something else? Please explain. You are spending lots of time and effort to get these macro variables, and that may not be necessary.
Thanks a huge. But I have to say my SAS/computer has problem NOW.
1) I run you code, the put line does not show up the value[see below], as seen in your log.
2) run a simple code below, it complains.
3) The code I am running on giganttttic data does not change any. It used to be ok!
_______________________________________________________________________
proc sql;
select case when horsepower>210 then 1 else 0 end as is_big, "big flag" as flag_note, count(*) as cttot
from sashelp.cars
group by 1,2;
quit;___________________________________________________
9121 proc sql;
9122 select case when horsepower>210 then 1 else 0 end as is_big, "big flag" as flag_note, count(*)
-
22
200
9122! as cttot
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
a numeric constant, a datetime constant, a missing value, (, *, +, -, BTRIM,
CALCULATED, CASE, EXISTS, INPUT, NOT, PUT, SUBSTRING, TRANSLATE, USER, ^, ~.
ERROR 200-322: The symbol is not recognized and will be ignored.
9123 from sashelp.cars
9124 group by 1,2;
9125 quit;
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
————————————————————————
9092 options mprint symbolgen;
9093
9094 %macro pctvar(ds, var, note);
9095 proc univariate data=&ds. noprint;
9096 var &var.;
9097 output out=a pctlpre=¬e._p_ pctlpts= 5 to 95 by 5;
9098 run;
9099
9100 data _null_;
9101 set a;
9102 array ¬e._p_ ¬e._p_:;
9103 do over ¬e._p_;
9104 call symputx(vname(¬e._p_), ¬e._p_, 'g');
9105 end;
9106 run;
9107
9108 proc sql;
9109 drop table a;
9110 quit;
9111
9112 %put "p_5=&&¬e._p_5. p_50=&&¬e._p_50. p_95=&&¬e._p_95.";
9113 %mend;
9114
9115 %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
SYMBOLGEN: Macro variable DS resolves to sashelp.cars
MPRINT(PCTVAR): proc univariate data=sashelp.cars noprint;
SYMBOLGEN: Macro variable VAR resolves to horsepower
MPRINT(PCTVAR): var horsepower;
SYMBOLGEN: Macro variable NOTE resolves to hp
MPRINT(PCTVAR): output out=a pctlpre=hp_p_ pctlpts= 5 to 95 by 5;
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.02 seconds
cpu time 0.01 seconds
MPRINT(PCTVAR): data _null_;
MPRINT(PCTVAR): set a;
SYMBOLGEN: Macro variable NOTE resolves to hp
SYMBOLGEN: Macro variable NOTE resolves to hp
MPRINT(PCTVAR): array hp_p_ hp_p_:;
SYMBOLGEN: Macro variable NOTE resolves to hp
MPRINT(PCTVAR): do over hp_p_;
SYMBOLGEN: Macro variable NOTE resolves to hp
SYMBOLGEN: Macro variable NOTE resolves to hp
MPRINT(PCTVAR): call symputx(vname(hp_p_), hp_p_, 'g');
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.02 seconds
cpu time 0.03 seconds
MPRINT(PCTVAR): proc sql;
MPRINT(PCTVAR): drop table a;
NOTE: Table WORK.A has been dropped.
MPRINT(PCTVAR): quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
MLOGIC(PCTVAR): %PUT "p_5=&&¬e._p_5. p_50=&&¬e._p_50. p_95=&&¬e._p_95."
SYMBOLGEN: Macro variable NOTE resolves to hp
SYMBOLGEN: Macro variable NOTE resolves to hp
SYMBOLGEN: Macro variable NOTE resolves to hp
"p_5=&&hp_p_5. p_50=&&hp_p_50. p_95=&&hp_p_95."
%pctvar(sashelp.cars, horsepower, hp);
%macro pctvar(ds, var, note);
proc univariate data=&ds. noprint;
var &var.;
output pctlpre=p_¬e._ pctlpts= 5 to 95 by 5;
run;
proc print; run;
data _null_;
set;
array p_¬e._ p_¬e._:;
do over p_¬e._;
call symputx(vname(p_¬e._),p_¬e._,'G');/*G=global?*/
end;
stop;
run;quit;
%put "p_5=&&p_¬e._5. p_50=&&p_¬e._50. p_95=&&p_¬e._95.";
%mend;
To tell you the truth, I am surprised this macro ever worked.
I have modified it so that it works FOR ME, and I use explicit (rather than implicit) data set names and array references. I have also put the call to the macro AFTER the definition of the macro.
Which brings up the question, why would you want to store statistical output in macro variables anyway? Why don't you just leave them in the SAS data set?
%macro pctvar(ds, var, note);
proc univariate data=&ds. noprint;
var &var.;
output pctlpre=¬e._p_ pctlpts= 5 to 95 by 5 out=a;
run;
data _null_;
set a;
array ¬e._p_ ¬e._p_:;
do i=1 to dim(¬e._p_);
call symputx(vname(¬e._p_(i)),¬e._p_(i));
end;
run;
%put p_5=&&¬e._p_5 p_50=&&¬e._p_50 p_95=&&¬e._p_95;
%mend;
%pctvar(sashelp.cars, horsepower, hp)
Thanks, But I run you code and get the below(does not show up the percentile value at the end).
I assign the percentile values to macro variables and use them down the stream.
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.01 seconds
cpu time 0.01 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.02 seconds
cpu time 0.01 seconds
MLOGIC(PCTVAR): %PUT p_5=&&¬e._p_5 p_50=&&¬e._p_50 p_95=&&¬e._p_95
p_5=&&hp_p_5 p_50=&&hp_p_50 p_95=&&hp_p_95
MLOGIC(PCTVAR): Ending execution.
1. This log/code doesn't show the error you've initially posted.
2. CALL SYMPUTX() takes 3 parameters (third is optional). You've only used two, which means you're creating local macro variables only available within the current macro. Use the third parameter to create global macro variables. Variable Scope is the term you need here.
3. If you're doing binning, I recommend PROC RANK instead but for other reporting, the macro variables may be necessary.
Can I bother you correct the macro below?!
Let the line, %put "p_5=&&p_¬e._5. p_50=&&p_¬e._50. p_95=&&p_¬e._95.";,
print out the 5/50/95 percentile of horsepower/sashelp.cars ?!
%macro pctvar(ds, var, note);
proc univariate data=&ds. noprint;
var &var.;
output pctlpre=p_¬e._ pctlpts= 5 to 95 by 5;
run;
proc print; run;
data _null_;
set;
array p_¬e._ p_¬e._:;
do over p_¬e._;
call symputx(vname(p_¬e._),p_¬e._,'G');/*G=global?*/
end;
stop;
run;quit;
%put "p_5=&&p_¬e._5. p_50=&&p_¬e._50. p_95=&&p_¬e._95.";
%mend;
%pctvar(sashelp.cars, horsepower, hp);
After this line in the log
MLOGIC(PCTVAR): %PUT p_5=&&¬e._p_5 p_50=&&¬e._p_50 p_95=&&¬e._p_95
I see the following line in the log
p_5=115 p_50=210 p_95=340
That's what you want, right?????
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.