Data visualization with SAS programming

using second y2axis with proc sgplot vbar

Reply
Frequent Contributor
Posts: 99

using second y2axis with proc sgplot vbar

Hi all,
I am creating 2 vbars for actual and predicted sales using proc sgplot, I have the code and able to get perfect graph but it uses common y-axis.
I want different y-axis for actual and predicted.

Thanks for all your help.

Regards,

Amit

code:

data test;
set sashelp.prdsal2 (keep= monyr actual predict year);
where year eq 1995;
run;
proc summary data=test missing nway;
class monyr;
var actual predict;
output out=summary (drop= _type_ _freq_ ) sum=;
run;
proc sgplot data=summary;
vbar monyr / response=actual
fillattrs=graphdata2 transparency=.65
legendlabel="Actual Sales" name="Actual";

vbar monyr / response=predict
barwidth=.5 fillattrs=graphdata2 transparency=.25 name="Predict"
legendlabel="Predicted Sales" name="Predict";
keylegend "Actual" "Predict";
xaxis label=" " grid;
yaxis label=" " discreteorder=data;
run;
SAS Super FREQ
Posts: 925

Re: using second y2axis with proc sgplot vbar

Hey Amit,

Currently, you cannot assign bar charts to secondary axes. However, you may be able to work around this depending on what you're trying to achieve. Why are you trying to asign the "predict" response to the Y2 axis? Is it just for axis labeling?

Thanks!
Frequent Contributor
Posts: 99

Re: using second y2axis with proc sgplot vbar

Hi Dan,
The data which I actually want to model have varying frequency.

for example say the Actual sales were in the thousands where as the predicted sales were in the hunreds. The small numbers (predicted) are not visible due to the large scale of Actual sales.

What would be a good way to represent it and show.

Thanks,

Amit
SAS Super FREQ
Posts: 925

Re: using second y2axis with proc sgplot vbar

I modified your original example. Try these possibilities:

/* Veritcally oriented */
proc sgplot data=summary;
vbar monyr / response=actual fillattrs=graphdata2 transparency=.65
legendlabel="Actual Sales" name="Actual";

vline monyr / response=predict y2axis markers markerattrs=(symbol=circlefilled)
legendlabel="Predicted Sales" name="Predict";
keylegend "Actual" "Predict";
y2axis min=0 label=" " offsetmin=0;
xaxis label=" " grid ;
yaxis label=" " offsetmin=0 discreteorder=data; run;


/* Horizontally oriented */
proc sgplot data=summary;
hbar monyr / response=actual fillattrs=graphdata2 transparency=.65
legendlabel="Actual Sales" name="Actual";

hline monyr / response=predict x2axis markers markerattrs=(symbol=circlefilled)
legendlabel="Predicted Sales" name="Predict";
keylegend "Actual" "Predict";
x2axis min=0 label=" " offsetmin=0;
yaxis label=" " grid ;
xaxis label=" " offsetmin=0 discreteorder=data; run;
Frequent Contributor
Posts: 99

Re: using second y2axis with proc sgplot vbar

Hi Dan,
Thanks a lot.

Regards,

Amit
Ask a Question
Discussion stats
  • 4 replies
  • 2748 views
  • 0 likes
  • 2 in conversation