I have a report with 5 graphs (all different variables). I used proc scscatter because all graphs need to be on the same page. One problem I am running into is that I want to customize the axes on all of the graphs so that they are more uniform.
Code created to generate graphs:
proc sgscatter data=ten;
plot (Hosp_admit_ma PctAdmit7_LF peds_prop icu_prop vent_prop)*date / join markerattrs=(size=1);
where "&start."d <= date <= "&end."d;
run;
Graphs:
You need to define what you mean by "more uniform".
Apparently 4 of your y variables are percentages, which mean underlying values between 0 and 1 (0% to 100 %) and the fifth variable has a much larger range of values, around 40 to 70. So just getting those to be uniform is very problematic.
Adding UNISCALE=X should make the horizontal axis the same in all plots but you are going to have to make some serious decisions about what to do with the Y values.
Does this really need to be 5 separate plots? I might reshape the data a bit to have a variable that indicates what the percentage values represent and use that variable as a Group variable to overlay them. Then use the count data overlayed in the same plot against a second yaxis.
Something like:
data reshape; set ten; array p (*) PctAdmit7_LF peds_prop icu_prop vent_prop; do i=1 to dim(p); groupvar=vname(p[i]); /* could use Vlabel to have the label of the variable appear in the legend instead of the name but would need to specify a length for the groupvar variable first */ pctvalue= p[i]; output; end; keep groupvar pctvalue Hosp_admit_ma date; run; proc sgploet data=reshape; series x=date y=pctvalue/group=groupvar; series x=date y=Hosp_admit_ma/ yaxis2; run;
You would use Xaxis and Yaxis / Yaxis2 statements to control the appearance of the axis.
May need to work with KEYLEGEND and some other options to get the legend as desired but worry about that if this is close to useful.
Proc SGSCATTER does not allow for axis control of the individual plots. You can use GTL (Graph Template Language) to achieve this. Proc SGSCATTER has the TMPLOUT= option to save the GTL used to create the graph. Adapt this code based on this example https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatgraph/n0n10xwfn3h4hnn10v5joeerd9m8.h....
To give you an idea, here is an example:
/*
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatgraph/n0n10xwfn3h4hnn10v5joeerd9m8.htm#p0z5nlcjy9hsnxn1ibiivnshllel
*/
/* Create the stock data for Microsoft for the years 2001 and 2002 */
data stockyear1 stockyear2;
set sashelp.stocks(where=(stock eq "Microsoft" and year(date) in (2001 2002)));
volume = volume/1000000;
volumePct = volume / 100;
if year(date) = 2001 then
output work.stockyear1;
else if year(date)=2002 then
output work.stockyear2;
run;
data msstock;
merge work.stockyear1(rename=(date=year1date close=year1close volume=year1vol))
work.stockyear2(rename=(date=year2date close=year2close volume=year2vol volumePct=year2volpct));
format year1date year2date monname3. year1close year2close dollar6. year2volpct percent9.1 ;
run;
ods path (prepend) work.mytemplates (update);
/* Create the graph template */
proc template;
define statgraph graphlattice;
begingraph;
entrytitle "Microsoft Stock Performance in 2001 and 2002";
layout lattice / columns=2 columngutter=5 rowgutter=5;
/* Column headers */
column2headers;
entry textattrs=GraphData1(weight=bold size=9pt) "Year 2001";
entry textattrs=GraphData2(weight=bold size=9pt) "Year 2002";
endcolumn2headers;
/* Row 1 content (cells 1-2) */
layout overlay /
xaxisopts=(display=(ticks tickvalues)
timeopts=(viewmax='01DEC2001'd tickvalueformat=monname3.))
yaxisopts=(
label="Closing Price"
linearopts=(viewmin=30 viewmax=80 tickvaluesequence=(start=30 end=80 increment=10))
);
seriesplot x=year1date y=year1close / display=all smoothconnect=true
lineattrs=GraphData1 markerattrs=GraphData1;
endlayout;
layout overlay /
xaxisopts=(display=(ticks tickvalues)
timeopts=(viewmax='01DEC2002'd tickvalueformat=monname3.))
yaxisopts=(
label="Closing Price"
linearopts=(viewmin=30 viewmax=80 tickvaluesequence=(start=30 end=80 increment=10))
);
seriesplot x=year2date y=year2close / display=all smoothconnect=true
lineattrs=GraphData2 markerattrs=GraphData2;
endlayout;
/* Row 2 content (cells 3-4) */
layout overlay /
xaxisopts=(display=(ticks tickvalues)
timeopts=(viewmax='01DEC2001'd tickvalueformat=monname3.))
yaxisopts=(label="Volume (Millions)");
needleplot x=year1date y=year1vol / displaybaseline=off
lineattrs=GraphData1;
endlayout;
layout overlay /
xaxisopts=(display=(ticks tickvalues)
timeopts=(viewmax='01DEC2002'd tickvalueformat=monname3.))
yaxisopts=(
label="Volume as %"
linearopts=(viewmin=0 viewmax=1.5 tickvaluesequence=( start=0 end=1.5 increment=0.25))
);
seriesplot x=year2date y=year2volpct / lineattrs=GraphData2;
endlayout;
endlayout;
endgraph;
end;
run;
proc sgrender data=msstock template=graphlattice;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.