BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hellohere
Pyrite | Level 9

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)?!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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;
--
Paige Miller

View solution in original post

15 REPLIES 15
PaigeMiller
Diamond | Level 26

Explain in more detail. Show us a sample of the input data. Show us a mocked up version of the desired output.

--
Paige Miller
hellohere
Pyrite | Level 9

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;

PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
hellohere
Pyrite | Level 9

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;

PaigeMiller
Diamond | Level 26
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;
--
Paige Miller
hellohere
Pyrite | Level 9
any way to enforce the size of the outcome picture?! THX
See, stitch this way, 4 picture together, you still need scroll down-up-left-right to see all details.
If just fit the SAS OUTPUR window and no need to scroll, that would be perfect.
PaigeMiller
Diamond | Level 26
ods graphics/height=3in width=4in;

 

You can play with the width and height to find the numbers that look best in your situation.

--
Paige Miller
hellohere
Pyrite | Level 9
Thanks, It almost saved my day. BUT I tried below with varied inch #, the outcome picture
is same size... any help?


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;

ods layout gridded columns=2 rows=2 advance=proc;
ods graphics/height=1in width=2in;
proc gplot data=temp; plot y1*x; run;
proc gplot data=temp; plot y2*x; run;
proc gplot data=temp; plot y3*x; run;
proc gplot data=temp; plot y4*x; run;
ods layout end;
PaigeMiller
Diamond | Level 26

You need to use PROC SGPLOT and the proper syntax in the SCATTER or SERIES command.

 

This will not work with PROC GPLOT.

--
Paige Miller
ballardw
Super User

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

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
hellohere
Pyrite | Level 9
Any way to save the picture with specified filename and file location, such as c:\mypic\_pic_today_01.jpg/png ?! Thanks,
Ksharp
Super User
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;

Ksharp_0-1658148642831.png

 

hellohere
Pyrite | Level 9
This is the one, one picture. Thanks,

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 15 replies
  • 1738 views
  • 1 like
  • 4 in conversation