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

 

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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

7 REPLIES 7
ballardw
Super User

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.

ChristosK
Quartz | Level 8

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

 

ballardw
Super User

@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;
ChristosK
Quartz | Level 8

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
ballardw
Super User

@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/

Reeza
Super User

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

 

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

ChristosK
Quartz | Level 8

Thanks Reeza, this is fantastic!

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
  • 7 replies
  • 8027 views
  • 3 likes
  • 3 in conversation