BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mariko5797
Pyrite | Level 9

I want to display the fit statistics for each CHMI group in the same colors that correspond with the plotted data points and regression lines. I.e., I want fit1 to be blue, fit2 to be gold, fit3 to be gray, and fit4 to be red. Is there a way to get individual colors for each line of text? I tried multiple inset lines but ended up with the text overlapping each other.

 

/*Get R- and p-value*/
ods exclude all;
proc sort data= _cpcr_; by aperiodc; run;
proc glm data= _cpcr_;
 by aperiodc;
 *class aperiodc;
 model max_temp = aval;
 ods output ModelANOVA= anova FitStatistics= fit;
run;
ods select all;

data _tmp_;
 merge fit anova(where= (HypothesisType= 3));
 by aperiodc;
 	fit= "R="||put(sqrt(RSquare), 5.3)||", p="||put(ProbF, 5.3);

data _null_;
 set _tmp_;
 	if aperiodc = 'CHMI 1' then call symput('fit1', strip(fit));
		else if aperiodc = 'CHMI 2' then call symput('fit2', strip(fit));
		else if aperiodc = 'CHMI 3' then call symput('fit3', strip(fit));
		else if aperiodc = 'CHMI 4' then call symput('fit4', strip(fit));
run;
%put &=fit1 &=fit2 &=fit3 &=fit4;

/*Plot Data*/
ods graphics on / attrpriority= none;
proc sgplot data= _cpcr_;
 styleattrs datacolors= (blue gold gray red)
			datacontrastcolors= (blue gold gray red)
 			datasymbols= (asterisk circle plus star)
			datalinepatterns= (solid mediumdash dashdotdot shortdashdot);
 reg y= max_temp x= aval / group= aperiodc clm clmtransparency= 0.8;
 	xaxis label= "Maximum Parasite Density" grid;
	yaxis label= "Oral Temperature" grid;
	keylegend / title= "CHMI";
	inset  ("R="="&fit1" 
			"R="="&fit2" 
			"R="="&fit3"
			"R="="&fit4")/ position= bottomright;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

The best way to do this is to use legend items to build your own "text" legend. Here is a simple example:

 

 

proc sgplot data=sashelp.class;
vbar age / group=sex groupdisplay=cluster;
legenditem name="line1" type=text / text="R=" label="0.5" textattrs=(color=red) labelattrs=(color=red);
legenditem name="line2" type=text / text="R=" label="0.8" textattrs=(color=blue) labelattrs=(color=blue);
keylegend "line1" "line2" / location=inside across=1;
run;

 

 

View solution in original post

1 REPLY 1
DanH_sas
SAS Super FREQ

The best way to do this is to use legend items to build your own "text" legend. Here is a simple example:

 

 

proc sgplot data=sashelp.class;
vbar age / group=sex groupdisplay=cluster;
legenditem name="line1" type=text / text="R=" label="0.5" textattrs=(color=red) labelattrs=(color=red);
legenditem name="line2" type=text / text="R=" label="0.8" textattrs=(color=blue) labelattrs=(color=blue);
keylegend "line1" "line2" / location=inside across=1;
run;

 

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 909 views
  • 5 likes
  • 2 in conversation