Learning SAS? Welcome to the exclusive online community for all SAS learners.

Cannot produce a line-connected series plot with SD bars in SGPLOT

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

Cannot produce a line-connected series plot with SD bars in SGPLOT

With an appropriate fussy data step I can get SD bars on a SCATTER plot in SGPLOT using the YERRORUPPER and YERRORLOWER options, but the only lines I can fit appear to be regression lines with REG. Apprently I can't connect the points with line segments.  The other kinds of line graph in SGPLOT (VLINE and SERIES) don't appear to support YERRORUPPER and YERRORLOWER.  Any suggestions?  This deficiency is quite serious, if there is no solution.  I would have to add lines manually in Powerpoint.

 

Will


Accepted Solutions
Solution
‎01-06-2017 03:03 AM
Super User
Posts: 10,023

Re: Cannot produce a line-connected series plot with SD bars in SGPLOT

Posted in reply to WillTheKiwi
It is easy for SGPLOT.




data class;
 set sashelp.class sashelp.class;
 if age in (12 13 14);
run;


proc sql;
create table have as
select age,sex,mean(weight) as mean,min(weight) as min,max(weight) as max
 from class
  group by age,sex;
quit;

ods graphics/reset attrpriority=none;
proc sgplot data=have;
styleattrs datasymbols=(circlefilled trianglefilled);
scatter x=age y=mean/group=sex groupdisplay=cluster clusterwidth=0.2 
  yerrorlower=min yerrorupper=max  ;
series x=age y=mean/group=sex groupdisplay=cluster clusterwidth=0.2
 markers  markerattrs=(size=12)  lineattrs=(pattern=solid) name='x';
 keylegend 'x';
run;


x.png

View solution in original post


All Replies
Super User
Posts: 19,772

Re: Cannot produce a line-connected series plot with SD bars in SGPLOT

Posted in reply to WillTheKiwi

Since you can easily overlay plots, you can create your error bars as their own 'plot' by using a symbol IBEAM instead and a scatter statement. I also wonder if you can use a custom graph as an marker symbol...

 

Are these plots you're trying to create a one off or do you produce them regularly? If regularly, I would strongly recommend proc template and sgreneder instead since you'll have more control over the graphics. GTL is definitely harder to learn but its incredibly powerful. 

 

https://support.sas.com/documentation/cdl/en/grstatug/69747/HTML/default/viewer.htm#p0328w2thtrwkhn1...

 

Highly Customized Graphs Using ODS Graphics

http://support.sas.com/resources/papers/proceedings16/12260-2016.pdf

 

 

Or there's also the ODS Graphics Editor which will generate the code. This is from a Base SAS installation - I believe you said you had access to SAS 9.4 Base SAS? If so, the code you generate there should work in SAS UE - minus your font issue. 

 

http://blogs.sas.com/content/graphicallyspeaking/2016/12/15/ods-graphics-designer/

 


WillTheKiwi wrote:

 Any suggestions?  This deficiency is quite serious, if there is no solution.  I would have to add lines manually in Powerpoint.

 

Will


 

You tend to jump to this fairly often, there is a definite trade off in terms of programming a graph vs manual point and click in terms of time and accuracy. If you feel programming is not worth the effort then perhaps you shouldn't go down this road at all. 

 

Contributor
Posts: 66

Re: Cannot produce a line-connected series plot with SD bars in SGPLOT

Thanks, Reeza. Time series connected by line segments would likely be the
most common kind of graph in the biomedical disciplines: such graphs are the
default for randomized controlled trials. Both your suggested solutions
sound promising, but not for casual SAS users of the kind SAS is presumably
trying to attract from R and SPSS. It seems to me that some work needs to
be done here, urgently.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Contributor
Posts: 66

Re: Cannot produce a line-connected series plot with SD bars in SGPLOT

Thanks, Reeza. Time series connected by line segments would likely be the
most common kind of graph in the biomedical disciplines: such graphs are the
default for randomized controlled trials. Both your suggested solutions
sound promising, but not for casual SAS users of the kind SAS is presumably
trying to attract from R and SPSS. It seems to me that some work needs to
be done here, urgently.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Posts: 19,772

Re: Cannot produce a line-connected series plot with SD bars in SGPLOT

Posted in reply to WillTheKiwi

http://support.sas.com/kb/42/542.html

 

From 2011. If it's not on the SAS ballot you can always add it. 

Contributor
Posts: 66

Re: Cannot produce a line-connected series plot with SD bars in SGPLOT

Thanks for the link to the code for generating and plotting the SE bars
(http://support.sas.com/kb/42/542.html). I had generated similar code. Note
however that SEs should NEVER be shown or plotted. It should always be SDs
in the case of means, or confidence intervals in the case of effects.
Anyway, the problem, as you know, is line segments connecting the points,
rather than regression lines.

Thanks also for your suggestion about putting it in the SAS ballot. If
someone from SAS is reading this, they should realize that it is not a
question of going into a ballot. It's a serious oversight that needs to be
fixed in the next update.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Contributor
Posts: 66

Re: Cannot produce a line-connected series plot with SD bars in SGPLOT

Thanks for the link to the code for generating and plotting the SE bars
(http://support.sas.com/kb/42/542.html). I had generated similar code. Note
however that SEs should NEVER be shown or plotted. It should always be SDs
in the case of means, or confidence intervals in the case of effects.
Anyway, the problem, as you know, is line segments connecting the points,
rather than regression lines.

Thanks also for your suggestion about putting it in the SAS ballot. If
someone from SAS is reading this, they should realize that it is not a
question of going into a ballot. It's a serious oversight that needs to be
fixed in the next update.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Posts: 10,023

Re: Cannot produce a line-connected series plot with SD bars in SGPLOT

Posted in reply to WillTheKiwi
Can you post a picture to explain what you are looking for ?


proc sql;
create table have as
select age,mean(weight) as mean,min(weight) as min,max(weight) as max
 from sashelp.class
  group by age;
quit;
proc sgplot data=have;
scatter x=age y=mean/ yerrorlower=min yerrorupper=max markerattrs=(symbol=circlefilled);
series x=age y=mean;
run;

Contributor
Posts: 66

Re: Cannot produce a line-connected series plot with SD bars in SGPLOT

See attached for a default graph generated by my spreadsheet for controlled trials at http://www.sportsci.org/2006/wghcontrial.htm. Such graphs also needs cleaning up with Powerpoint. (Since Office 2007 that has become quite a challenge, because all lines in Excel now become narrow-gauge railway tracks when the graph is ungrouped in Powerpoint.)


example of ccontrolled trial.JPG
Super User
Posts: 19,772

Re: Cannot produce a line-connected series plot with SD bars in SGPLOT

Posted in reply to WillTheKiwi

Is this the graph you're trying to replicate in SAS?

Contributor
Posts: 66

Re: Cannot produce a line-connected series plot with SD bars in SGPLOT

Yes, that's the kind of graph, but not with those data specifically. So
it's a time series (or several such) connected with line segments and
showing SD bars. If you use SCATTER in SGPLOT, you can get SD bars but no
line segments. If you use SERIES, you can get symbols with line segments
but no SD bars. If you use VLINE, you get line segments but no symbols and
no SD bars. Well, that seems to be the state of affairs, if I haven't missed
something.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Contributor
Posts: 66

Re: Cannot produce a line-connected series plot with SD bars in SGPLOT

Yes, that's the kind of graph, but not with those data specifically. So
it's a time series (or several such) connected with line segments and
showing SD bars. If you use SCATTER in SGPLOT, you can get SD bars but no
line segments. If you use SERIES, you can get symbols with line segments
but no SD bars. If you use VLINE, you get line segments but no symbols and
no SD bars. Well, that seems to be the state of affairs, if I haven't missed
something.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Solution
‎01-06-2017 03:03 AM
Super User
Posts: 10,023

Re: Cannot produce a line-connected series plot with SD bars in SGPLOT

Posted in reply to WillTheKiwi
It is easy for SGPLOT.




data class;
 set sashelp.class sashelp.class;
 if age in (12 13 14);
run;


proc sql;
create table have as
select age,sex,mean(weight) as mean,min(weight) as min,max(weight) as max
 from class
  group by age,sex;
quit;

ods graphics/reset attrpriority=none;
proc sgplot data=have;
styleattrs datasymbols=(circlefilled trianglefilled);
scatter x=age y=mean/group=sex groupdisplay=cluster clusterwidth=0.2 
  yerrorlower=min yerrorupper=max  ;
series x=age y=mean/group=sex groupdisplay=cluster clusterwidth=0.2
 markers  markerattrs=(size=12)  lineattrs=(pattern=solid) name='x';
 keylegend 'x';
run;


x.png
☑ This topic is solved.

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

Discussion stats
  • 12 replies
  • 919 views
  • 2 likes
  • 3 in conversation