Question

I am new to SAS and want to make a macro procedure that creates y-axis values for a later PROC GPLOT.

In plain English, there are two posssible minimum values (and maxs) on this graph. The axis range is dependent on which minimum value is the smallest. Otherwise, SAS will not display data outside the axis range. I do NOT want SAS to automatically create the range for me. I want to define the range myself.

So, this is my attempt at a procedure that a) calculates two minimum values, b) compares the two, and c) stores the smaller of the two in a new macro variable. If I can get this one to work, a max procedure would be easy to do.

%MACRO min;
%LET ymin1 = %SYSEVALF(&minresult - (((&minresult + &maxresult)/2) * .05);
%PUT ymin1 = &ymin1;
%LET ymin2 = %SYSEVALF(&min - (&min * .05));
%PUT ymin2 = &ymin2;
%IF &ymin1 > &ymin2
%THEN %LET ymin = ymin2;
%ELSE %LET ymin = ymin1;
%PUT ymin = &ymin;
%MEND min;

I have a feeling I am doing something wrong syntactically. Any help is appreciated.

Was it helpful?

Solution

The simple solution is to skip the %if stuff and just define ymin from ymin1/2:

%let ymin = %sysfunc(min(&ymin1,&ymin2));

The specific syntax error you have, other than a missing ) in the first ymin declaration, is that %let ymin = ymin2; should be %let ymin=&ymin2;. Otherwise it just contains the text "ymin2", not the contents of the macro variable.

The entire macro:

%MACRO min(minresult,maxresult,min,max);
%LET ymin1 = %SYSEVALF(&minresult - (((&minresult + &maxresult)/2) * .05));
%PUT ymin1 = &ymin1;
%LET ymin2 = %SYSEVALF(&min - (&min * .05));
%PUT ymin2 = &ymin2;
%let ymin = %sysfunc(min(&ymin1,&ymin2));
%PUT ymin = &ymin;
%MEND min;

%min (5,6,3,4);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top