Data visualization with SAS programming

insert Spearman Coefficient and P value into a graph by using proc template

Reply
Frequent Contributor
Posts: 78

insert Spearman Coefficient and P value into a graph by using proc template

Hi All,

 

I wrote a dynamic template to draw scatter plots, but I want to add coefficient and p value into the figure. The coefficient and p value can be anywhere in the figure. Like what I did now, it's above the figure, but I insert the values manually one by one. Any idea to input then quickly? my goal is just show the values in the figure, I don't care the type, the location or some other things. I just don't want input manually. Below is my template.Code with bold are what I want to change.

 

proc template;
/* Create the plot template. */
define statgraph testPattern;
begingraph / designheight = 8in;
dynamic var1 var2 var3;
layout lattice / columns = 1 rows = 2 rowgutter = 20 columngutter = 20;
/* */
cell;
cellheader;
layout gridded / border = true;
entry "Toddler S = 0.518 p = <.001; Young S = 0.383 p = <.001" / textattrs = (weight = bold);
entry "Child S = 0.428 p = <.001; Teen S = 0.383 p = <.001" / textattrs = (weight = bold);
endlayout;
endcellheader;
layout overlay / yaxisopts = (label = var1 labelattrs = (weight = bold size = 8pt) tickvalueattrs = (weight = bold))
xaxisopts = (label = var3 labelattrs = (weight = bold) tickvalueattrs = (weight = bold));
scatterplot y=var1 x=var3 / group=group;
regressionplot y=var1 x=var3 / group = group name="lines";
discretelegend "lines";
endlayout;
endcell;
cell;
cellheader;
layout gridded / border = true;
entry "Toddler S = 0.517 p = <.001; Young S = 0.383 p = <.001" / textattrs = (weight = bold);
entry "Toddler S = 0.377 p = <.001; Young S = 0.318 p = 0.002" / textattrs = (weight = bold);
endlayout;
endcellheader;
layout overlay / yaxisopts = (label = var2 labelattrs = (weight = bold size = 8pt) tickvalueattrs = (weight = bold))
xaxisopts = (label = var3 labelattrs = (weight = bold) tickvalueattrs = (weight = bold));;
scatterplot y=var2 x=var3 / group=group;
regressionplot y=var2 x=var3 / group=group name="lines";
discretelegend "lines";
endlayout;
endcell;
endlayout;
endgraph;
end;
run;
/* Generate the plot. */
options orientation=landscape;
ods rtf file="scattertest1.rtf";

proc sgrender data=combine template='testPattern';
dynamic var1 = 'P_SCD_SCORE_PH' var2 = 'P_SCD_SCORE_PI' var3 = 'P_SCD_SCORE_PMC';
run;
ods rtf close;scatter plot.png

Super User
Posts: 11,101

Re: insert Spearman Coefficient and P value into a graph by using proc template

Looks like you may want more dynamic variables

Frequent Contributor
Posts: 78

Re: insert Spearman Coefficient and P value into a graph by using proc template

Yes, that a method. But as you can see, in the two entrys statement, I need 8 dymanic variables, and these variables are in another dataset which I run out. I thought there maybe have simpler way to add coefficient and p value in the graph.

 

Thanks,

C

Super Contributor
Posts: 252

Re: insert Spearman Coefficient and P value into a graph by using proc template

Hi C,

 

I would use into: with proc sql to obtain the pvalues.

 

And then use the nmvar or mvar statement to plot those p-values. So it's quite similar to what you've done already, but instead of manually entereing the numbers, the numbers are already in a macro variable.

 

Also you don't have to use the nmvar or mvar statement.

 

You could also just use something like this:

 

entry "Toddler S = 0.518 p = &pvalue1; Young S = 0.383 p = &pvalue2" / textattrs = (weight = bold);

 

After creating the pvalue1 and pvalue2 macro variables.

 

The code in this paper shows how I've created macro variables with the into clause and then displayed those values on the plot.

 

http://support.sas.com/resources/papers/proceedings13/243-2013.pdf

 

Many thanks,

 

Kriss  

Super Contributor
Posts: 252

Re: insert Spearman Coefficient and P value into a graph by using proc template

Hi C,

 

I would use into: with proc sql to obtain the pvalues.

 

And then use the nmvar or mvar statement to plot those p-values. So it's quite similar to what you've done already, but instead of manually entereing the numbers, the numbers are already in a macro variable.

 

Also you don't have to use the nmvar or mvar statement.

 

You could also just use something like this:

 

entry "Toddler S = 0.518 p = &pvalue1; Young S = 0.383 p = &pvalue2" / textattrs = (weight = bold);

 

After creating the pvalue1 and pvalue2 macro variables.

 

The code in this paper shows how I've created macro variables with the into clause and then displayed those values on the plot.

 

http://support.sas.com/resources/papers/proceedings13/243-2013.pdf

 

Many thanks,

 

Kriss  

Ask a Question
Discussion stats
  • 4 replies
  • 165 views
  • 0 likes
  • 3 in conversation