DATA Step, Macro, Functions and more

proc sgplot, plotting OR's and CI

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 77
Accepted Solution

proc sgplot, plotting OR's and CI

[ Edited ]

 

This seems to simple but thought I should ask anyway:

 

I have values for an OR  and 95% CI already worked out, and want to plot these OR's on the y axis with time of event on the x axis .

 

proc sgplot data =VPPlotsforSAS1 (where=(level=1));
scatter x=Vasoplegia_Time y=OR /
group=Blood_Pressure groupdisplay=cluster clusterwidth=0.5;
xaxis type =discrete;
run;

 

How do I create a whisker plot or forrest plot with the upper or lower or both CI's connected with a line to the OR point estimate?


Accepted Solutions
Solution
‎02-14-2018 01:38 PM
Super User
Posts: 13,304

Re: proc sgplot, plotting OR's and CI

Posted in reply to ChristosK

ChristosK wrote:

Thanks for that.

Unfortunately that won't work in this case because my OR is a point estimate as are my Confidence intervals. I do not have a numeric continuous variable to plot on the Y axis .

 

Have seen may iterations of the solution you mention but not one that will plot a line between my specified OR extimate and the CI's

 



Do you or do you not have upper confidence limits at the x variable for your OR vales? You have to have something to attempt to plot, so what is it. Your OR is already getting plotted against a continuous y axis.

Perhaps you want two series plots connecting the upper and lower limits.

Or maybe  a Band plot along with that scatter.

 

In the following example y is your OR variable and the yupper and ylower are the limits of the confidence interval. The limits are connected to the limits. If you don't like the appearance of the limit lines then the ERRORBARATTRS style elements control color, line type and thickness of the line.

data junk;
   do x= 1 to 10;
      y= 50*rand('uniform');
      yupper= 1.05*y;
      ylower= .95*y;
      output;
   end;
run;

proc sgplot data=junk;
   scatter x=x y=y/yerrorupper=yupper yerrorlower=ylower;
run;

View solution in original post


All Replies
Super User
Posts: 13,304

Re: proc sgplot, plotting OR's and CI

Posted in reply to ChristosK

If you have separate variables that contain the upper and lower limit you want to display then the options Yerrorupper=upperlimitvariable yerrorlower=lowerlimitvariable as options on your scatter statement should do what you want.

 

But if your are using an older version of SAS this may not work depending on the version as there have been many additions to graphing options in recent releases.

Frequent Contributor
Posts: 77

Re: proc sgplot, plotting OR's and CI

Thanks for that.

Unfortunately that won't work in this case because my OR is a point estimate as are my Confidence intervals. I do not have a numeric continuous variable to plot on the Y axis .

 

Have seen may iterations of the solution you mention but not one that will plot a line between my specified OR extimate and the CI's

 

Solution
‎02-14-2018 01:38 PM
Super User
Posts: 13,304

Re: proc sgplot, plotting OR's and CI

Posted in reply to ChristosK

ChristosK wrote:

Thanks for that.

Unfortunately that won't work in this case because my OR is a point estimate as are my Confidence intervals. I do not have a numeric continuous variable to plot on the Y axis .

 

Have seen may iterations of the solution you mention but not one that will plot a line between my specified OR extimate and the CI's

 



Do you or do you not have upper confidence limits at the x variable for your OR vales? You have to have something to attempt to plot, so what is it. Your OR is already getting plotted against a continuous y axis.

Perhaps you want two series plots connecting the upper and lower limits.

Or maybe  a Band plot along with that scatter.

 

In the following example y is your OR variable and the yupper and ylower are the limits of the confidence interval. The limits are connected to the limits. If you don't like the appearance of the limit lines then the ERRORBARATTRS style elements control color, line type and thickness of the line.

data junk;
   do x= 1 to 10;
      y= 50*rand('uniform');
      yupper= 1.05*y;
      ylower= .95*y;
      output;
   end;
run;

proc sgplot data=junk;
   scatter x=x y=y/yerrorupper=yupper yerrorlower=ylower;
run;
Frequent Contributor
Posts: 77

Re: proc sgplot, plotting OR's and CI

Thank you, that worked out very nicely.

 

Just one other question:

 

proc sgplot data =VPPlotsforSAS1 (where=(level=1));
scatter x=Vp y=OR / yerrorupper=UCL errorbarattrs
colorresponse = startcolor=blue NEUTRALCOLOR=yellow ENDCOLOR=aliceblue
/* yerrorlower=LCL */
group=Blood_Pressure groupdisplay=cluster clusterwidth=0.5;
xaxis type =discrete;
run;

 

I'm getting an error message here 

ERROR 73-322: Expecting an =.
ERROR 76-322: Syntax error, statement will be ignored.
It says I need to put an = sign, but there is one , and changing the number of spaces and brackets seems not to make a difference.
Im trying too assign pre-specified colours for the three blood pressures that are clustered at each level on the x axis
Super User
Posts: 13,304

Re: proc sgplot, plotting OR's and CI

[ Edited ]
Posted in reply to ChristosK

ChristosK wrote:

Thank you, that worked out very nicely.

 

Just one other question:

 

proc sgplot data =VPPlotsforSAS1 (where=(level=1));
scatter x=Vp y=OR / yerrorupper=UCL errorbarattrs
colorresponse = startcolor=blue NEUTRALCOLOR=yellow ENDCOLOR=aliceblue
/* yerrorlower=LCL */
group=Blood_Pressure groupdisplay=cluster clusterwidth=0.5;
xaxis type =discrete;
run;

 

I'm getting an error message here 

ERROR 73-322: Expecting an =.
ERROR 76-322: Syntax error, statement will be ignored.
It says I need to put an = sign, but there is one , and changing the number of spaces and brackets seems not to make a difference.
Im trying too assign pre-specified colours for the three blood pressures that are clustered at each level on the x axis

ERRORBARATTRS is likely the proximate cause of the error message as that option requires an = but you do not have one. Something like:

Errorbarattrs =(color=green pattern=dotdash)

 

If you want to change the errorbar attributes for each group then you may want to use a styleattrs statement or go all the way to a DATTRMAP data set. Errorbarattrs colors by default come from ContrastColor attribute in the current styles GraphDataN definitions. So you could use

Styleattrs  datacontrastcolors=(red green blue); to assign those contrast colors (which also affect things like vbar/hbar borders, marker outlines.

 

I don't think that colorresponse and colormodel are what you really want unless you want to apply a gradient color to markers of the scatter based on another variable.

The colorresponse should point to a variable with a numeric value that indicates where in the color gradient you want a value (the procedure automatically scales to the gradient)

 

The COLORMODEL would have the colors, either a style reference or a triplet of names with the first the Start color, second the "neutral" or midrange, and third the end color.

 

so your code would use

 

colormodel = (blue yellow aliceblue) colorresponse= somenumericvar

 

note that if you use colorresponse that GROUP will be ignored. If you need to show different bit for the group variable you might change to SGPANEL and use that variable as a PANELBY variable.

 

With a colormodel colorresponse you likely want to include a GRADLEGEND statement to have some explanation of the color range.

 

You may want to peruse here for some examples of graphs with data and code:

http://support.sas.com/sassamples/graphgallery/index.html

http://robslink.com/SAS/

Super User
Posts: 23,262

Re: proc sgplot, plotting OR's and CI

Posted in reply to ChristosK

https://blogs.sas.com/content/tag/forest-plot/

 

Several examples of exactly what you want in those posts, including examples of subgroup analysis.

Frequent Contributor
Posts: 77

Re: proc sgplot, plotting OR's and CI

Thanks Reeza, this is fantastic!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 120 views
  • 2 likes
  • 3 in conversation