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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
You probably submitted some code without the proper terminations. Restart SAS in a new session and start again to reset it or try the magic string.

https://blogs.sas.com/content/iml/2013/08/19/errors-that-cause-sas-to-freeze.html

https://communities.sas.com/t5/Programming-1-and-2/magic-string/td-p/681381

View solution in original post

19 REPLIES 19
Reeza
Super User
This means your macro code is not running fine.

Can you post the code? Or more of the log?
hellohere
Pyrite | Level 9

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=&&note._p_5. p_50=&&note._p_50. p_95=&&note._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=&note._p_ pctlpts= 5 to 95 by 5;
run;
proc print; run;
data _null_;
set;
array &note._p_ &note._p_:;
do over &note._p_;
call symputx(vname(&note._p_),&note._p_);
end;
stop;
run;quit;
%put "p_5=&&note._p_5. p_50=&&note._p_50. p_95=&&note._p_95.";
%mend;

ballardw
Super User

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=&&note._p_5. p_50=&&note._p_50. p_95=&&note._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=&note._p_ pctlpts= 5 to 95 by 5;
run;
proc print; run;
data _null_;
set;
array &note._p_ &note._p_:;
do over &note._p_;
call symputx(vname(&note._p_),&note._p_);
end;
stop;
run;quit;
%put "p_5=&&note._p_5. p_50=&&note._p_50. p_95=&&note._p_95.";
%mend;


 

hellohere
Pyrite | Level 9

The according percentile in the dataset from SAS

 

Obs p_hp_5 p_hp_10 p_hp_15 p_hp_20 p_hp_25 p_hp_30 p_hp_35 p_hp_40 p_hp_45 p_hp_50 p_hp_55 p_hp_60 p_hp_65 p_hp_70 p_hp_75 p_hp_80 p_hp_85 p_hp_90 p_hp_951
115130140155165172184193200210215224230240255275295302340
Reeza
Super User
%macro pctvar(ds, var, note);
proc univariate data=&ds. noprint;
var &var.;
output out=a pctlpre=&note._p_ pctlpts= 5 to 95 by 5;
run;

data _null_;
set a;
array &note._p_ &note._p_:;
do over &note._p_;
call symputx(vname(&note._p_), &note._p_, 'g');
end;
run;

proc sql;
drop table a;
quit;

%put "p_5=&&&note._p_5. p_50=&&&note._p_50. p_95=&&&note._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=&note._p_ pctlpts= 5 to 95 by 5;
 76         run;
 77         
 78         data _null_;
 79         set a;
 80         array &note._p_ &note._p_:;
 81         do over &note._p_;
 82         call symputx(vname(&note._p_), &note._p_, 'g');
 83         end;
 84         run;
 85         
 86         proc sql;
 87         drop table a;
 88         quit;
 89         
 90         %put "p_5=&&&note._p_5. p_50=&&&note._p_50. p_95=&&&note._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=&&note._p_5. p_50=&&note._p_50. p_95=&&note._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=&note._p_ pctlpts= 5 to 95 by 5;
run;
proc print; run;
data _null_;
set;
array &note._p_ &note._p_:;
do over &note._p_;
call symputx(vname(&note._p_),&note._p_);
end;
stop;
run;quit;
%put "p_5=&&note._p_5. p_50=&&note._p_50. p_95=&&note._p_95.";
%mend;


 

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
hellohere
Pyrite | Level 9

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=&note._p_ pctlpts= 5 to 95 by 5;
9098 run;
9099
9100 data _null_;
9101 set a;
9102 array &note._p_ &note._p_:;
9103 do over &note._p_;
9104 call symputx(vname(&note._p_), &note._p_, 'g');
9105 end;
9106 run;
9107
9108 proc sql;
9109 drop table a;
9110 quit;
9111
9112 %put "p_5=&&&note._p_5. p_50=&&&note._p_50. p_95=&&&note._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=&&&note._p_5. p_50=&&&note._p_50. p_95=&&&note._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."

Reeza
Super User
You probably submitted some code without the proper terminations. Restart SAS in a new session and start again to reset it or try the magic string.

https://blogs.sas.com/content/iml/2013/08/19/errors-that-cause-sas-to-freeze.html

https://communities.sas.com/t5/Programming-1-and-2/magic-string/td-p/681381
hellohere
Pyrite | Level 9

%pctvar(sashelp.cars, horsepower, hp);

 

%macro pctvar(ds, var, note);
proc univariate data=&ds. noprint;
var &var.;
output pctlpre=p_&note._ pctlpts= 5 to 95 by 5;
run;
proc print; run;
data _null_;
set;
array p_&note._ p_&note._:;
do over p_&note._;
call symputx(vname(p_&note._),p_&note._,'G');/*G=global?*/
end;
stop;
run;quit;
%put "p_5=&&p_&note._5. p_50=&&p_&note._50. p_95=&&p_&note._95.";
%mend;

PaigeMiller
Diamond | Level 26

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=&note._p_ pctlpts= 5 to 95 by 5 out=a;
run;
data _null_;
    set a;
    array &note._p_ &note._p_:;
    do i=1 to dim(&note._p_);
        call symputx(vname(&note._p_(i)),&note._p_(i));
    end;
run;
%put p_5=&&&note._p_5 p_50=&&&note._p_50 p_95=&&&note._p_95;
%mend;

%pctvar(sashelp.cars, horsepower, hp)

 

 

--
Paige Miller
hellohere
Pyrite | Level 9

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=&&&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

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.

hellohere
Pyrite | Level 9

Can I bother you correct the macro below?! 

Let the line, %put "p_5=&&p_&note._5. p_50=&&p_&note._50. p_95=&&p_&note._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_&note._ pctlpts= 5 to 95 by 5;
run;
proc print; run;
data _null_;
set;
array p_&note._ p_&note._:;
do over p_&note._;
call symputx(vname(p_&note._),p_&note._,'G');/*G=global?*/
end;
stop;
run;quit;
%put "p_5=&&p_&note._5. p_50=&&p_&note._50. p_95=&&p_&note._95.";
%mend;

 

%pctvar(sashelp.cars, horsepower, hp);

PaigeMiller
Diamond | Level 26

After this line in the log

 

MLOGIC(PCTVAR):  %PUT p_5=&&&note._p_5 p_50=&&&note._p_50 p_95=&&&note._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?????

--
Paige Miller

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
  • 3250 views
  • 2 likes
  • 5 in conversation