BookmarkSubscribeRSS Feed
rsilve
Calcite | Level 5

Hello All,

 

I am new to PROC TEMPLATE but I would like to create a scatterplot with regression lines overlayed. I have a categorical variable "comp" that has 3 values. I would like there to be 3 regression lines, one for each of these groups. Similarly, I would like the scatterplot to have different shapes and colors for each of the "comp" values.

 

When I run the code below, I get only 2 regression lines. Where am I going wrong? I am using SAS 9.3, and a sample of the data is attached to this message:

proc template;
define style Styles.BAPstyle; 
    parent=styles.listing;
    style GraphData1 from GraphData1 /
      ContrastColor=blue
      Color=blue
      MarkerSymbol="CircleFilled"
      Linestyle=1;
    style GraphData2 from GraphData2 /
      ContrastColor=orange
      Color=orange
      MarkerSymbol="TriangleFilled"
      Linestyle=2;
    style GraphData3 from GraphData3 /
      ContrastColor=black
      Color=black
      MarkerSymbol="SquareFilled"
      Linestyle=3;
  end;
run;


proc template;
define statgraph BAP;
begingraph ;
  entrytitle "Sector 1 Bland-Altman Plot";
  layout overlay / 
  		yaxisopts=(label="Difference between Measurements")
		xaxisopts = (label = "Measurement Average");
	scatterplot x = mean y = diff / 
		group = comp name = "diff";
	regressionplot x=mean y=diff /
        group=comp
        name="trends";
    discretelegend "trends" "diff"/ 
		title="Comparisons";
	referenceline Y = 0 / 
		CURVELABEL =  "Zero Bias Line" 
		CURVELABELLOCATION = Outside
		DATATRANSPARENCY = 0.5;
	referenceline Y = &upper / 
		CURVELABEL =  "95% Upper Limit" 
		CURVELABELLOCATION = Outside
		DATATRANSPARENCY = 0.5;
	referenceline Y = &lower / 
		CURVELABEL =  "95% Lower Limit" 
		CURVELABELLOCATION = Outside
		DATATRANSPARENCY = 0.5;
  endlayout;
endgraph;
end;
run;


proc sort data = test; by comp; run;
ods _all_ close;
ods graphics / reset imagename="Bland-Altman";
ods pdf file="&out.\fig1.pdf" style=BAPstyle;

proc sgrender data=test template=BAP;
	format comp $comp.;
run;
ods pdf close;
ods pdf;

Here is the plot that I get in return (notice the missing black line):

 

 

snip.JPG

 

Additionally, I would love suggestions on how to make a legend that grouped the scatterplot point with the corresponding line with the relevant label.

 

Thank you in advance!

2 REPLIES 2
DanH_sas
SAS Super FREQ

I think the third line is behind the blue line. To test this theory, change the REGRESSIONPLOT to LOESSPLOT and see if the line appears.

 

As for the legend, The labels will come from the group values, as the plots are grouped plots. Also, instead of DISCRETELEGEND, use MERGEDLEGEND with the names of the SCATTERPLOT and REGRESSIONPLOT. For example,

 

MERGEDLEGEND "trends" "diff" / title="Comparisons";

 

Hope this helps!

Dan

rsilve
Calcite | Level 5

Thanks for the suggestions, 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1074 views
  • 0 likes
  • 2 in conversation