I have one summarized time-series dataset with two cat-vars, and like to do n-by-M plot with SGPLOT.
data _temp;
do grp1=1 to 3;
do grp2=1 to 3;
do ind=1 to 100;
y=grp1*10+grp2+sin(ind/10); output;
end;
end;
end;
run;quit;
ods layout gridded columns=3 rows=3 advance=proc;
proc sgplot data=_temp;
by grp1 grp2;
series x=ind y=y/ lineattrs=( color=red thickness=2 pattern=solid);
run;quit;
ods layout end;
Somehow show up and 1*(n*m). Anyone can help?!
You want this ?
data _temp;
do grp1=1 to 3;
do grp2=1 to 3;
do ind=1 to 100;
y=grp1*10+grp2+sin(ind/10); output;
end;
end;
end;
run;quit;
proc sgpanel data=_temp;
panelby grp1 grp2/layout=lattice;
series x=ind y=y/ lineattrs=( color=red thickness=2 pattern=solid);
run;
If do as below, it shows up n-by-M. BUT grp1 info is lost.
ods layout gridded columns=3 rows=3 advance=proc;
proc sgplot data=_temp(where=(grp1=1));
by grp2;
series x=ind y=y/ lineattrs=( color=red thickness=2 pattern=solid);
run;quit;
proc sgplot data=_temp(where=(grp1=2));
by grp2;
series x=ind y=y/ lineattrs=( color=red thickness=2 pattern=solid);
run;quit;
proc sgplot data=_temp(where=(grp1=3));
by grp2;
series x=ind y=y/ lineattrs=( color=red thickness=2 pattern=solid);
run;quit;
ods layout end;
Anyway to show up grp1 info, with grp2 value?!
You want this ?
data _temp;
do grp1=1 to 3;
do grp2=1 to 3;
do ind=1 to 100;
y=grp1*10+grp2+sin(ind/10); output;
end;
end;
end;
run;quit;
proc sgpanel data=_temp;
panelby grp1 grp2/layout=lattice;
series x=ind y=y/ lineattrs=( color=red thickness=2 pattern=solid);
run;
And your code should look like this .
ods layout gridded columns=3 rows=3 advance=table; ods graphics /width=300px height=200px; proc sgplot data=_temp; by grp1 grp2; series x=ind y=y/ lineattrs=( color=red thickness=2 pattern=solid); run;quit; ods layout end;
This is better.
Why sgplot?
I would tend to use SGPANEL such as
proc sgpanel data=_temp; panelby grp1 grp2/layout=lattice; series x=ind y=y/ lineattrs=( color=red thickness=2 pattern=solid); run;quit;
Which, barring many values of grp1 and grp2 automatically creates the correct number of rows and columns. Note that Layout=lattice is for exactly 2 Panelby variables.
Thanks. I bet it works.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.