Data visualization with SAS programming

PROC TEMPLATE De-Bugging help

Reply
New Contributor
Posts: 2

PROC TEMPLATE De-Bugging help

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!

SAS Super FREQ
Posts: 896

Re: PROC TEMPLATE De-Bugging help

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

New Contributor
Posts: 2

Re: PROC TEMPLATE De-Bugging help

Thanks for the suggestions, 

 

Ask a Question
Discussion stats
  • 2 replies
  • 344 views
  • 0 likes
  • 2 in conversation