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 need generate 3-by-2 plots, which the code below does. BUT also need let the lines are with varied colors.

 

There are GROUPLC= and styleattrs datacontrastcolors=(red green black orange blue cyan);  BUT only for multiple lines within a single plot.

How to get 3-by-2 plots with controlled/varied colors?

 

Any other PROC is fine. 

 

Thanks,  

 

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

	ods layout gridded columns=3 rows=2 advance=bygroup;
	proc sgplot data=_test noautolegend uniform=xscale; 
	by grp;
	series x=ind y=yvalue / group=grp lineattrs=( thickness=2 pattern=solid) grouplc=grp ;     
	refline  30/axis=x lineattrs=(color=red thickness=2 pattern=solid); 
	run;
	ods layout end;
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data _test;
do grp=1 to 6;
	do ind=1 to 100;
		yvalue=sin(ind/10)+grp;
		gx=grp;
		output;
	end;
end;
run;quit;



data dattrmap;
infile cards truncover;
input id $ value :$20. linecolor $  ;
datalines;
x  1  red 
x  2  blue 
x  3  green 
x  4  yellow 
x  5  purple 
x  6  black 
;
run;


	ods layout gridded columns=3 rows=2 advance=bygroup;
	proc sgplot data=_test noautolegend uniform=xscale dattrmap=dattrmap; 
	by grp;
	series x=ind y=yvalue / group=grp lineattrs=( thickness=2 pattern=solid) attrid=x  ;     
	refline  30/axis=x lineattrs=(color=red thickness=2 pattern=solid); 
	run;
	ods layout end;

Ksharp_0-1757487441470.png

 

View solution in original post

1 REPLY 1
Ksharp
Super User
data _test;
do grp=1 to 6;
	do ind=1 to 100;
		yvalue=sin(ind/10)+grp;
		gx=grp;
		output;
	end;
end;
run;quit;



data dattrmap;
infile cards truncover;
input id $ value :$20. linecolor $  ;
datalines;
x  1  red 
x  2  blue 
x  3  green 
x  4  yellow 
x  5  purple 
x  6  black 
;
run;


	ods layout gridded columns=3 rows=2 advance=bygroup;
	proc sgplot data=_test noautolegend uniform=xscale dattrmap=dattrmap; 
	by grp;
	series x=ind y=yvalue / group=grp lineattrs=( thickness=2 pattern=solid) attrid=x  ;     
	refline  30/axis=x lineattrs=(color=red thickness=2 pattern=solid); 
	run;
	ods layout end;

Ksharp_0-1757487441470.png

 

sas-innovate-2026-white.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
  • 1 reply
  • 285 views
  • 0 likes
  • 2 in conversation