The following SAS9.3 code in macro:
/* A few extreme values of could distort graphical output.
Comparisons are made in succession from highest to next higher
value for the top 5 extreme values. If the highest value is larger than
twice the next higher value, then the highest value will be left out
of the graph by assigning Rmax to the next higher value. Rmax
specifies the maximum value of the graphical axis line
(xaxis or yaxis). */
ods select ExtremeValues;
Proc Univariate Data=&InDat NExtrVal=5;
Var &RType;
ods output ExtremeValues = ExtremeValues;
Run;
options mprint mlogic symbolgen;
Data _Null_;
Set ExtremeValues;
If _N_ = 1 Then Call Symputx('High5',High);
If _N_ = 2 Then Call Symputx('High4',High);
If _N_ = 3 Then Call Symputx('High3',High);
If _N_ = 4 Then Call Symputx('High2',High);
If _N_ = 5 Then Call Symputx('High1',High);
Run;
%Do I = 1 %To 4;
%If %Sysevalf(&&High&I/&&High%Eval(&I+1)) > 1.3 %Then %Let RMax = %Sysevalf(&&High%Eval(&I+1),ceil);
%End;
options nomprint nomlogic nosymbolgen;
It produces the correct value of RMax but there are log warnings:
MPRINT(NEGBININF): symbolgen;
MPRINT(NEGBININF): Data _Null_;
MPRINT(NEGBININF): Set ExtremeValues;
MPRINT(NEGBININF): If _N_ = 1 Then Call Symputx('High5',High);
MPRINT(NEGBININF): If _N_ = 2 Then Call Symputx('High4',High);
MPRINT(NEGBININF): If _N_ = 3 Then Call Symputx('High3',High);
MPRINT(NEGBININF): If _N_ = 4 Then Call Symputx('High2',High);
MPRINT(NEGBININF): If _N_ = 5 Then Call Symputx('High1',High);
MPRINT(NEGBININF): Run;
NOTE: There were 5 observations read from the data set WORK.EXTREMEVALUES.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
MLOGIC(NEGBININF): %DO loop beginning; index variable I; start value is 1; stop value is 4; by
value is 1.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 1
SYMBOLGEN: Macro variable HIGH1 resolves to 122.34597475
SYMBOLGEN: && resolves to &.
WARNING: Apparent symbolic reference HIGH not resolved.
SYMBOLGEN: Macro variable I resolves to 1
SYMBOLGEN: Macro variable HIGH2 resolves to 104.85413396
MLOGIC(NEGBININF): %IF condition %Sysevalf(&&High&I/&&High%Eval(&I+1)) > 1.3 is FALSE
MLOGIC(NEGBININF): %DO loop index variable I is now 2; loop will iterate again.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 2
SYMBOLGEN: Macro variable HIGH2 resolves to 104.85413396
SYMBOLGEN: && resolves to &.
WARNING: Apparent symbolic reference HIGH not resolved.
SYMBOLGEN: Macro variable I resolves to 2
SYMBOLGEN: Macro variable HIGH3 resolves to 77.716058462
MLOGIC(NEGBININF): %IF condition %Sysevalf(&&High&I/&&High%Eval(&I+1)) > 1.3 is TRUE
MLOGIC(NEGBININF): %LET (variable name is RMAX)
SYMBOLGEN: && resolves to &.
WARNING: Apparent symbolic reference HIGH not resolved.
SYMBOLGEN: Macro variable I resolves to 2
SYMBOLGEN: Macro variable HIGH3 resolves to 77.716058462
MLOGIC(NEGBININF): %DO loop index variable I is now 3; loop will iterate again.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 3
SYMBOLGEN: Macro variable HIGH3 resolves to 77.716058462
SYMBOLGEN: && resolves to &.
WARNING: Apparent symbolic reference HIGH not resolved.
SYMBOLGEN: Macro variable I resolves to 3
SYMBOLGEN: Macro variable HIGH4 resolves to 75.249510073
MLOGIC(NEGBININF): %IF condition %Sysevalf(&&High&I/&&High%Eval(&I+1)) > 1.3 is FALSE
MLOGIC(NEGBININF): %DO loop index variable I is now 4; loop will iterate again.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable I resolves to 4
SYMBOLGEN: Macro variable HIGH4 resolves to 75.249510073
SYMBOLGEN: && resolves to &.
WARNING: Apparent symbolic reference HIGH not resolved.
SYMBOLGEN: Macro variable I resolves to 4
SYMBOLGEN: Macro variable HIGH5 resolves to 59.803347257
MLOGIC(NEGBININF): %IF condition %Sysevalf(&&High&I/&&High%Eval(&I+1)) > 1.3 is FALSE
MLOGIC(NEGBININF): %DO loop index variable I is now 5; loop will not iterate again.
MPRINT(NEGBININF): options nomprint nomlogic
NOTE: Overwriting existing template/link: Sgdesign
NOTE: STATGRAPH 'Sgdesign' has been saved to: SASUSER.TEMPLAT
NOTE: PROCEDURE TEMPLATE used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Appearing to provide a warning for the line
%If %Sysevalf(&&High&I/&&High%Eval(&I+1)) > 1.3 %Then %Let RMax = %Sysevalf(&&High%Eval(&I+1),ceil);
Why?
Thanks Paige Miller! Code now doesn't log Warning messages. Oink! Oink! 🙂
&&high&i works as intended
&&high%eval(&i+1) does not work because it is not in the format &¯ovar&index
perhaps you want this
%let oink=%eval(&i+1);
&&high&oink
Thanks Paige Miller! Code now doesn't log Warning messages. Oink! Oink! 🙂
Could you please guide on below Error, I am comparing data and when matched setting a string to a variable
I need to send the result in an email, so I need value outside the code block.
SAS CODE:
DATA _NULL_;
if (10 EQ 10) then ValResult ="MATCHED" ; ValResult ="NOT MATCHED" ;
RUN;
%put &ValResult.;
LOG:
%put &ValResult.;
WARNING: Apparent symbolic reference VALRESULT not resolved.
&ValResult.
RESULT:
in results tab I am getting MATCHED
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: