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
proc template;
   define style mystyle;
   parent=styles.sasweb;
      class graphwalls / 
            frameborder=off;
      class graphbackground / 
            color=white;
   end;
run;
/* VBAR option    */
   ods listing close;
ods html style=mystyle path='.' file='newgraph.html';
ods graphics / reset=all border=off width=800 height=480;
   
   proc sgplot data=glm_MAP1 nowall noborder  ;

     title 'Linear Regression Models with Parameter estimates for MAP';
     styleattrs datacontrastcolors=(CX016381 CX1BC9FF CXFF7F00 CX814101  ) ;


vbar IV/ response= Param  group =DV groupdisplay =cluster  grouporder=data 
barwidth=0.3 ;

xaxis  discreteorder=data   ;

 run;

I have got as far as getting the bar plot positioned and sized correctly, although so far, only the vbarparm option seems to list choices for inserting an upper confidence limit (actually I'm trying to insert a recalculated SD).

 

Any ideas?

 

Also, is there a way to shade in the background  represented by the area behind the 1st 4 blue bars on the x axis ?

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

If you are using the VBARPARM example I gave you, you should be to add the LIMITUPPER option to it to reference your SD variable. As for the labeling, if you are trying to label using the bar value, you can just use the DATALABEL option to turn them on, and the DATALABELPOS to position is above or below the bar (they can't be right no top of the bar when you have limits). If you want to show the SD values (or show both the bar and SD values), I would just use an XAXISTABLE as you mentioned.

 

Thanks!

Dan

View solution in original post

19 REPLIES 19
DanH_sas
SAS Super FREQ

For pre-calculated values, VBARPARM or HBARPARM is your best option. Is there any particular reason why you do not want to use those statements? As for the colored region, there are a couple of possibilities, but the best option depends on your version of SAS. Which version do you have?

 

Thanks!

Dan

ChristosK
Quartz | Level 8

vbarparm does not give me the option to specify "group=DV", and generally seems to have many less options.

instead of group, it suggests using a category statement but I keep in getting additional errors when I replace vbar with vbarparm.

 

I'll try experimenting with HBARPARM

DanH_sas
SAS Super FREQ

Try this and see if it works for you:

 

proc sgplot data=glm_MAP1 nowall noborder  ;
     title 'Linear Regression Models with Parameter estimates for MAP';
     styleattrs datacontrastcolors=(CX016381 CX1BC9FF CXFF7F00 CX814101  ) ;
vbarparm category=IV response= Param /  group =DV groupdisplay =cluster  grouporder=data 
barwidth=0.3 ;

xaxis  discreteorder=data   ;

 run;
ChristosK
Quartz | Level 8

I'm using SAS Studio, and it is up to date.

DanH_sas
SAS Super FREQ

Please run the following from the editor and post the result from the log:

 

%put &sysvlong;

 

Thanks!

Dan

ChristosK
Quartz | Level 8
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73          %put &sysvlong;
 9.04.01M5P091317
 74         
 75         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 88         

I ran this just after the last code for the bar table

DanH_sas
SAS Super FREQ

Since you are using SAS 9.4m5, I can show you a cool new way to shade those bars 🙂 The REFLINE statement has a new option called DISCRETETHICKNESS, which gives you the ability to size the reference lines relative to the midpoint spacing. Setting size=1 will make the lines touch from one midpoint to the other. So, in your case:

 

proc sgplot data=glm_MAP1 nowall noborder  ;
     title 'Linear Regression Models with Parameter estimates for MAP';
     styleattrs datacontrastcolors=(CX016381 CX1BC9FF CXFF7F00 CX814101  ) ;
refline "rMAP_Nexmean" "rMAP_LAmean" "rMAP_UAmean" "rMAP_LLmean" / 
            discretethickness=1 lineattrs=(color=pink) axis=x;
vbarparm category=IV response= Param /  group =DV groupdisplay =cluster  
            grouporder=data barwidth=0.3 ;
xaxis  discreteorder=data   ;
run;

Let me know if you have any issues with this example.

 

Thanks!
Dan

ChristosK
Quartz | Level 8

Dan:

 

Didn't realize that the SAS studio version I have is effectively the same as Base 9.4 M5.

Pink colour was great, thats a useful function, much appreciated.

 

I still have a variance which is the SD that I'd like to plot as a single "upper whisker" on each of the bars.

 

Can you even label the top of each bar with a numeric value? I'll probably just do an xaxis table if anything at all, but the main objective is to be able to place confidence bands or a whisker centered on the top of the bar.

DanH_sas
SAS Super FREQ

If you are using the VBARPARM example I gave you, you should be to add the LIMITUPPER option to it to reference your SD variable. As for the labeling, if you are trying to label using the bar value, you can just use the DATALABEL option to turn them on, and the DATALABELPOS to position is above or below the bar (they can't be right no top of the bar when you have limits). If you want to show the SD values (or show both the bar and SD values), I would just use an XAXISTABLE as you mentioned.

 

Thanks!

Dan

ChristosK
Quartz | Level 8

That worked. Didn't see that previous response.

 

However.. when I try and place the SD value as the whisker, usually the line lies within the space occupied by the bar.

If I use the upper limit of the 95% CI it looks like it should.

 

Perhaps I should just add that SD to the mean value of the parameter estimate value that we are plotting on the y axis.

 

thanks for showing me these new options.

 

Christos

ChristosK
Quartz | Level 8
proc template;
   define style mystyle;
   parent=styles.sasweb;
      class graphwalls / 
            frameborder=off;
      class graphbackground / 
            color=white;
   end;
run;

ods listing close;
ods html style=mystyle path='.' file='newgraph.html';
ods graphics / reset=all border=off width=480 height=800;
   
   proc sgplot data=glm_MAP2 nowall noborder  ;

      title 'Linear Regression Models with Parameter estimates and SD for MAP';
      styleattrs datacontrastcolors=(CX016381 CX1BC9FF CXFF7F00 CX814101  ) ;


refline "rMAP_Nexmean" "rMAP_LAmean" "rMAP_UAmean" "rMAP_LLmean" / 
            discretethickness=1 lineattrs=(color=pink) axis=y;
hbarparm category=IV  response= Param / group =DV groupdisplay =cluster  grouporder=data 
barwidth=0.4  clusterwidth=1   limitupper=SD_Param    ;

yaxis  discreteorder=data label =".";
keylegend / position=bottom location=outside position=bottomright  autoitemsize title='Time of Sampling' noborder ;  

 run;

Dan:

 

I transposed the axes  but the pink bar is no longer visible. Cant see what the error is.

 

DanH_sas
SAS Super FREQ

It not obvious from your code, so it could be related to something else, such as your data. Try setting TYPE=DISCRETE on you YAXIS statement and see if that helps.

ChristosK
Quartz | Level 8

That didn't work.

Might try entering a y2axis and setting alternate colorbands for each of the sampling times 

DanH_sas
SAS Super FREQ

I created a simple test similar to yours, and it worked for me. Can you post another picture and the PROC CONTENTS output of your data set?

 

Thanks!

Dan

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 19 replies
  • 2326 views
  • 6 likes
  • 2 in conversation