Thank you
data have;
infile cards expandtabs truncover;
input Sample_name :$20. Replicate $ Read_Mean Read_std;
YERRORUPPER=Read_Mean+1.96*Read_std;
YERRORLOWER=Read_Mean-1.96*Read_std;
cards;
Ad-Ct25 En 99.9981137 0.004001
Ad-Ct25 Mg 99.8808502 0.077763
Ad-Ct28 En 99.8575861 0.241182
Ad-Ct28 Mg 92.0169639 1.59308
Ad-Ct31 En 93.3995416 3.462698
Ad-Ct31 Mg 55.0308563 7.835461
Ad-Ct34 En 42.7004962 8.213055
Ad-Ct34 Mg 16.445265 3.89857
;
proc sgplot data=have;
vbarparm category=Sample_name response=Read_Mean/group=Replicate nooutline groupdisplay=cluster displaybaseline=off;
scatter x=Sample_name y=Read_Mean/YERRORUPPER=YERRORUPPER YERRORLOWER=YERRORLOWER
group=Replicate groupdisplay=cluster markerattrs=(size=0) ERRORBARATTRS=(thickness=2) ;
run;
Use VBARBASIC instead of VBAR to allow use of series or scatter and bar graph in the same graph.
I am not sure what you mean by "Do I need to have low and high columns?". If you are looking at setting the upper/lower value of an error bar then that might be the YERRORUPPER and YERRORLOWER options in the SCATTER plot.
As @ballardw was saying, you can use vbarbasic to render the mean-calculated bar chart and allow a scatter overlay. The VBARPARM statement also has more flexible overlay support, but you would have to do the calculation outside of the procedure. You will need high and low columns to hold the limit values for your scatter plot. The code will looks something like the following:
Here is my data and below is my graph. Not sure how to calculate high, low values for StDev from Read_std. I want to show my Read_std range on the top of vbar to show the range like in blue ?
Sample_name | Replicate | Read_Mean | Read_std |
Ad-Ct25 | En | 99.9981137 | 0.004001 |
Ad-Ct25 | Mg | 99.8808502 | 0.077763 |
Ad-Ct28 | En | 99.8575861 | 0.241182 |
Ad-Ct28 | Mg | 92.0169639 | 1.59308 |
Ad-Ct31 | En | 93.3995416 | 3.462698 |
Ad-Ct31 | Mg | 55.0308563 | 7.835461 |
Ad-Ct34 | En | 42.7004962 | 8.213055 |
Ad-Ct34 | Mg | 16.445265 | 3.89857 |
I would create a little data step to calculate the high and lows relative to the mean. Something like this:
data main_subset2;
set main_subset;
high = read_mean + read_std;
low = read_mean - read_std;
run;
Then, use main_subset2 in your SGPLOT call. Use the HIGH and LOW variables in the YERRORUPPER and YERRORLOWER options, respectively.
data have;
infile cards expandtabs truncover;
input Sample_name :$20. Replicate $ Read_Mean Read_std;
YERRORUPPER=Read_Mean+1.96*Read_std;
YERRORLOWER=Read_Mean-1.96*Read_std;
cards;
Ad-Ct25 En 99.9981137 0.004001
Ad-Ct25 Mg 99.8808502 0.077763
Ad-Ct28 En 99.8575861 0.241182
Ad-Ct28 Mg 92.0169639 1.59308
Ad-Ct31 En 93.3995416 3.462698
Ad-Ct31 Mg 55.0308563 7.835461
Ad-Ct34 En 42.7004962 8.213055
Ad-Ct34 Mg 16.445265 3.89857
;
proc sgplot data=have;
vbarparm category=Sample_name response=Read_Mean/group=Replicate nooutline groupdisplay=cluster displaybaseline=off;
scatter x=Sample_name y=Read_Mean/YERRORUPPER=YERRORUPPER YERRORLOWER=YERRORLOWER
group=Replicate groupdisplay=cluster markerattrs=(size=0) ERRORBARATTRS=(thickness=2) ;
run;
Perfect. Thank you so much ballardw, Dan and Ksharp. This is exactly what I need.
@Dan, Sorry for my delayed reposnse, I was trying on my real data where the response values are very low (0.002) for one replicate and 99.9 for another replicate. Having hard time to show on the same scale. All is well now. Thank you
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.