BookmarkSubscribeRSS Feed
AmitKB
Fluorite | Level 6
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;
4 REPLIES 4
DanH_sas
SAS Super FREQ
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!
AmitKB
Fluorite | Level 6
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
DanH_sas
SAS Super FREQ
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;
AmitKB
Fluorite | Level 6
Hi Dan,
Thanks a lot.

Regards,

Amit

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 4957 views
  • 0 likes
  • 2 in conversation