Say there is dataset contains X and 4Ys(Y1, Y2,Y3, and Y4).
How to generate a chart with 4-sub-charts (Y1~X, Y2~X, Y3~X and Y4~X)?!
ods layout gridded columns=2 rows=2 advance=proc;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_1 x=cycle;
run;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_2 x=cycle;
run;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_3 x=cycle;
run;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_4 x=cycle;
run;
ods layout end;
Explain in more detail. Show us a sample of the input data. Show us a mocked up version of the desired output.
One X with 4 Ys. One way is to plot 4Ys(below) with X within one chart.
When 4 Ys' Range varies and plot together does not make sense,
I like to make one chart with 4 carpets, each charting one Y with the same X
(SAS generate one Picture)
data temp;
do x=1 to 20;
y1=ranuni(1);y2=ranuni(2);y3=ranuni(3);y4=ranuni(4);
output;
end;
run;quit;
symbol1 interpol=join;symbol2 interpol=join;symbol3 interpol=join;symbol4 interpol=join;
proc gplot data=temp;
plot (y1 y2 y3 y4)*x/legend overlay;
run;quit;
First, your subject line is very misleading, there is no 2x2 charting in your question, and this confused me greatly. I suggest you go back to your original post and change it so that it has a more meaningful subject line.
Next, you provide data that really doesn't illustrate the problem. There's no different range of these 4 Y variables and they all fit nicely on one plot with one y-axis. As a recommendation to you, it is very helpful to provide data that illustrates your problem. It's never a good idea to make us guess.
Nevertheless at the risk of guessing wrong, here's some data that maybe closer to what you described, and a potential plot that might look better — but again, I am requesting that you tell us what you want instead of making us guess. Be specific, be detailed, be clear.
data temp;
do x=1 to 20;
y1=ranuni(1);
y2=10*ranuni(2);
y3=100*ranuni(3);
y4=1000*ranuni(4);
output;
end;
run;
proc sgplot data=temp;
series x=x y=y1;
series x=x y=y2;
series x=x y=y3;
series x=x y=y4;
yaxis type=log logstyle=logexpand logbase=10;
run;
What wanted is stich the 4 plots into one(one pic/jpg), so that 4 takes four corners with the
final chart(top_left, top_right, bottom_left and bottom_right).
proc gplot data=sashelp.applianc(where=(cycle<=20));
plot units_1*cycle/legend overlay;
run;quit;
proc gplot data=sashelp.applianc(where=(cycle<=20));
plot units_2*cycle/legend overlay;
run;quit;
proc gplot data=sashelp.applianc(where=(cycle<=20));
plot units_3*cycle/legend overlay;
run;quit;
proc gplot data=sashelp.applianc(where=(cycle<=20));
plot units_4*cycle/legend overlay;
run;quit;
ods layout gridded columns=2 rows=2 advance=proc;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_1 x=cycle;
run;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_2 x=cycle;
run;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_3 x=cycle;
run;
proc sgplot data=sashelp.applianc(where=(cycle<=20));
scatter y=units_4 x=cycle;
run;
ods layout end;
ods graphics/height=3in width=4in;
You can play with the width and height to find the numbers that look best in your situation.
You need to use PROC SGPLOT and the proper syntax in the SCATTER or SERIES command.
This will not work with PROC GPLOT.
@PaigeMiller wrote:
You need to use PROC SGPLOT and the proper syntax in the SCATTER or SERIES command.
This will not work with PROC GPLOT.
At least not without the headaches of Proc Template to create the display template and Proc GREPLAY to associate each already create plot with a designated space in the template.
PROC TEMPLATE + PROC GREPLAY is needed to replace ODS LAYOUT GRIDDED. I don't think that was clear from what you wrote.
The simplicity of ODS LAYOUT GRIDDED seems to win hands down here.
data temp;
do x=1 to 20;
y1=ranuni(1);
y2=10*ranuni(2);
y3=100*ranuni(3);
y4=1000*ranuni(4);
output;
end;
run;
proc sgscatter data=temp;
plot (y1-y4)*x;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: