I have a question about proc sgplot. I want to use macro variables to set the range of proc sgplot in the values option of the YAXIS statement,e.g., values=(&minv. to &maxv. by 1). When I do this the data plotted on the yaxis of the plot are off from the actual data values, usually by about $1. When I replace the macro variables in the values option with actual numbers, e.g., values=(140 to 175 by 1) then the plotted y-axis values match the data. Has this been seen before? Is there a resolution? I tried valueshint option but this did not seem to work.
I instead tried min=&minv. max=&maxv. and this will work, however, I have not been able to find a way to set the plotted incremental values on the yaxis,but these go by a default to values larger than $1. I tried INTERVAL option,for this case, but it does not seem to work in the case of continuous numerical values, just categorical ones like "week_date" [say each Monday date for a series of weeks].
I'm not certain if the resolution of this is easy or not. I have looked on the internet. Any ideas of how to possibly resolve this?
Thank you,
Eric
This means that your YAXIS is getting tick value 148-174. Earlier, you said you wanted 148-175. To get that, you will need to round up the max value in PROC SQL before you assign it to the macro variable. Try this and see if it works for you:
proc sql noprint;
select min(varchk1),round(max(varchk1),1) into :minv1, :maxv1
from range_limit1v2;
quit;
I have a question about proc sgplot. I want to use macro variables to set the range of proc sgplot in the values option of the YAXIS statement,e.g., values=(&minv. to &maxv. by 1). When I do this the data plotted on the yaxis of the plot are off from the actual data values, usually by about $1.
Show us the code where the macro variables are created and the entire PROC SGPLOT (not just the YAXIS statement) code. Show us what happens. Include a screen capture of the plot in your reply (not as an attachment).
Just to be sure things a substituting the way you think they are, set OPTIONS MPRINT; so that you can see the statement in the log with the values substituted. Let us know what you see.
Thanks!
Dan
Hi Dan,
It listed as:
467 YAXIS valuesformat=data GRID LABEL="CAD/CWT" VALUES=(&minv. to &maxv. by 1) valueshint ;
SYMBOLGEN: Macro variable MINV resolves to 148
SYMBOLGEN: Macro variable MAXV resolves to 174.21
Apparently, the macro vaiables resolved.
Thank you,
Eric
I think that the decimal part of MAXV might be what's causing your issue, since it is not evenly divisible by 1. To verify this, use the TMPLOUT option on your SGPLOT statement and see the list of values generated for TICKVALUELIST.
proc sgplot data=whatever TMPLOUT="mygraph.sas";
...
run;
Hi Dan,
This is what I am getting. Not certain of interpretation:
proc template;
define statgraph sgplot;
begingraph / collation=binary subpixel=on;
EntryTitle "AFSC versus CanFax Forecasted Prices for WLPIP Fed Cattle" /;
layout overlay / x2axisopts=(labelFitPolicy=Split) xaxisopts=( Label="Expiration Date" labelFitPolicy=Split type=linear linearopts=( tickvaluelist=( 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ) viewmin=12 viewmax=37 ) griddisplay=on ) yaxisopts=( Label="CAD/CWT" type=linear linearopts=( tickvaluelist=( 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 ) TickValueFormat=DATA ) griddisplay=on ) x2axisopts=(labelFitPolicy=Split);
BandPlot X=Wks_to_Exp LimitUpper=positive1 LimitLower=negative1 / DataTransparency=0.75 FillAttrs=GraphConfidence(Color=CXFF0000) LegendLabel="Band" NAME="BAND";
BandPlot X=Wks_to_Exp LimitUpper=positive2 LimitLower=negative2 / DataTransparency=0.75 FillAttrs=GraphConfidence(Color=CX0000FF) LegendLabel="Band" NAME="BAND1";
SeriesPlot X=Wks_to_Exp Y=AFSC_Forecasted_Price / primary=true Lineattrs=( Color=CX0000FF Pattern=1 Thickness=3) LegendLabel="AFSC" NAME="A";
SeriesPlot X=Wks_to_Exp Y=Canfax_Forecasted_Price / Lineattrs=( Color=CXFF0000 Pattern=1 Thickness=3) LegendLabel="CanFax" NAME="B";
DiscreteLegend "A" "B" / Location=Outside valign=bottom;
endlayout;
endgraph;
end;
run;
Thank you,
Eric
This means that your YAXIS is getting tick value 148-174. Earlier, you said you wanted 148-175. To get that, you will need to round up the max value in PROC SQL before you assign it to the macro variable. Try this and see if it works for you:
proc sql noprint;
select min(varchk1),round(max(varchk1),1) into :minv1, :maxv1
from range_limit1v2;
quit;
Hi Dan,
After checking about 7 points they now appear to be matching as far as I can discern by reading the plot.
Thank you for finding this solution!
Regards,
Eric
The macro variables are generated this way:
proc sql noprint;
select min(varchk1),max(varchk1) into :minv1, :maxv1
from range_limit1v2;
quit;
%Put &minv1.;
%Put &maxv1.;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.