BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ericoneill
Calcite | Level 5

    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

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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;

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
ericoneill
Calcite | Level 5
Hi Paige,

I don't think I can post possibly proprietary information. I am just curious if replacing literal numeric values in

Values,e.g., VALUES=(140 to 175 by 1) with VALUES=(&min. to &max. by 1) could cause a mismatch between

a sasdata set and plotted values in proc sgplot.

Thank you for commenting,

Eric


DanH_sas
SAS Super FREQ

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

ericoneill
Calcite | Level 5
Hi Dan,

Here is the log. It appears to be resolving properly:

[cid:image001.png@01D5B194.7A2AF750]

Thanks for interest in issue,

Eric


ericoneill
Calcite | Level 5

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

DanH_sas
SAS Super FREQ

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;

ericoneill
Calcite | Level 5

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

DanH_sas
SAS Super FREQ

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;

ericoneill
Calcite | Level 5

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

ericoneill
Calcite | Level 5

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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 3426 views
  • 0 likes
  • 3 in conversation