BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hellohere
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?!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
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

 

View solution in original post

6 REPLIES 6
hellohere
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?!

Ksharp
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

 

Ksharp
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

 

hellohere
Pyrite | Level 9

This is better.

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

hellohere
Pyrite | Level 9

Thanks. I bet it works. 

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
  • 6 replies
  • 371 views
  • 2 likes
  • 3 in conversation