BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hellohere
Pyrite | Level 9
	ods layout gridded columns=2 rows=3 advance=proc;
	proc sgplot data=ts_pout_xrs1(where=(ind between &stind. and &endind.));
	by xrs_flag1;
	series x=ind y=ts_out /lineattrs=(color=random thickness=2 pattern=solid);  
	refline  &minind./axis=x;
	run;quit;
	ods layout end;

I have  time-series summary by xrs_flag1 with 6 groups. Like to plot these 6 into 2-by-3 layout.

HOWEVER it does not (show up at 1*6 in seq). Also the lines have the same color for all. 

How to SGPlot n-by-m with varied color ?!

 

Thanks, 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Custom graph questions go much better with some example data. Many times a new variable(s) or changes in the data structure are needed to accomplish the desire.

Best is to provide example data in the form of working data step code and include only the variables related to the question.

Or use one of the SAS supplied data sets such as SASHELP.Class or SASHELP.CARS.

 

To show graphs in a 2x3 layout better would likely be Proc SGPanel with your XRS_flag1 variable as the Panelby variable and layout options on the panel by for colums=2 and rows =3 (or vice versa depending, some people reverse the order in discussion).

The Plot statement would look basically the same but could use a GROUP=XRX_flag1 to get different colors, remove the Color= option from the Lineattrs options.

 

I might start with something like:

proc sgpanel data=ts_pout_xrs1(where=(ind between &stind. and &endind.));
	panelby xrs_flag1/ onepanel columns=3 ;
	series x=ind y=ts_out / group=xrs_flag1 lineattrs=( thickness=2 pattern=solid);  
	refline  &minind./axis=x;
	run;

 

View solution in original post

5 REPLIES 5
ballardw
Super User

Custom graph questions go much better with some example data. Many times a new variable(s) or changes in the data structure are needed to accomplish the desire.

Best is to provide example data in the form of working data step code and include only the variables related to the question.

Or use one of the SAS supplied data sets such as SASHELP.Class or SASHELP.CARS.

 

To show graphs in a 2x3 layout better would likely be Proc SGPanel with your XRS_flag1 variable as the Panelby variable and layout options on the panel by for colums=2 and rows =3 (or vice versa depending, some people reverse the order in discussion).

The Plot statement would look basically the same but could use a GROUP=XRX_flag1 to get different colors, remove the Color= option from the Lineattrs options.

 

I might start with something like:

proc sgpanel data=ts_pout_xrs1(where=(ind between &stind. and &endind.));
	panelby xrs_flag1/ onepanel columns=3 ;
	series x=ind y=ts_out / group=xrs_flag1 lineattrs=( thickness=2 pattern=solid);  
	refline  &minind./axis=x;
	run;

 

hellohere
Pyrite | Level 9

Thanks, this works.

 

BTW, how to auto-scale in y-axis for each?!  Though they are aligned up, I need auto-scale each y-axis. 

 

SGPanel1.png

hellohere
Pyrite | Level 9
Spoiler
Thanks. It works on auto-scale.

But how to let each plot has varied color?


data _test;
do grp=1 to 6;
	do ind=1 to 100;
		yvalue=sin(ind)+grp;
		output;
	end;
end;
run;quit;

ods printer printer=png300 file="bygroups.png" style=normalprinter;
ods layout gridded columns=3 rows=2 advance=bygroup
    column_gutter=0.1in row_gutter=0.1in;
ods graphics / width=2in;
title "_test by grp";
proc sgplot data=_test noautolegend uniform=xscale;
by grp;
series x=ind y=yvalue / group=grp lineattrs=( thickness=2 pattern=solid);     
	refline  30/axis=x;
run;
ods layout end;
ods printer close;

bygroups.png

Ksharp
Super User

OK. That is need a some sophisticated skill "DATTRMAP= option" .

options nodate nonumber;
options papersize=(7.35in 5.75in);
options leftmargin="0.001in" rightmargin="0.001in";
options nobyline;

data heart;
set sashelp.heart;
if (weight_status eq '') then weight_status="Unknown";
run;
proc sort data=heart; by weight_status; run;

title "Cholesterol Distribution by Weight Status";



data dattrmap;
infile cards truncover;
input id $ value :$20. linecolor $  ;
datalines;
x  Normal  red 
x  Overweight  blue 
x  Underweight  green 
;
run;





ods printer printer=png300 file="bygroups.png" style=normalprinter;
ods layout gridded columns=2 rows=2 advance=bygroup
    column_gutter=0.1in row_gutter=0.1in;
ods graphics / width=3.5in ;
title "#byval1";
proc sgplot data=heart noautolegend uniform=xscale  dattrmap=dattrmap ;
by weight_status;
yaxis offsetmin=0.05;
series x=weight y=height / group=weight_status attrid=x;
run;
ods layout end;
ods printer close;

Ksharp_0-1757486117037.png

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 5 replies
  • 252 views
  • 0 likes
  • 3 in conversation