cancel
Turn on suggestions
Showing results for
Search instead for
Did you mean:
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Pyrite | Level 9

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

0 Likes
1 ACCEPTED SOLUTION

Accepted Solutions
Super User

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;

Ksharp_0-1762938276815.png

6 REPLIES 6
Pyrite | Level 9

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

0 Likes
Super User

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;

Ksharp_0-1762938276815.png

Super User

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;	

Ksharp_0-1762938667981.png

Pyrite | Level 9

This is better.

0 Likes
Super User

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.

0 Likes
Pyrite | Level 9

Thanks. I bet it works.

0 Likes

sasinnovate.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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 lock in 2025 pricing—just 495ドル!

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.

SAS Training: Just a Click Away

Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
[フレーム]

AltStyle によって変換されたページ (->オリジナル) /