Hallo!
I would need some help to create a Graph with my data.
The dataset looks like this:
data have;
input ID $ co2 $ area area_under area_over;
datalines;
101 High 329274.45563 1161.4533333 328113.0023
101 Low 329807.07976 51867.348667 277939.7311
103 High 299940.79867 1437.205 298503.59367
103 Low 309707.27464 196061.47517 113645.79948
105 High 500296.11766 32079.163619 468216.95404
105 Low 330042.631 69774.392944 260268.23805;
Run;
and the graphS I would like to obtain like this:
N.1
where I have two vBars (one for every co2 level) and the blue part rapresent the percentage area_over/area and the red part rapresent the percentage area_under/area.
If possible I would also like to have a standard deviation bar.
N.2
The second Graph I would like to have looks like this
Thank you very much for your help!
Riccardo
Try the following and see if they meet your needs:
data have;
input ID $ co2 $ area area_under area_over;
datalines;
101 High 329274.45563 1161.4533333 328113.0023
101 Low 329807.07976 51867.348667 277939.7311
103 High 299940.79867 1437.205 298503.59367
103 Low 309707.27464 196061.47517 113645.79948
105 High 500296.11766 32079.163619 468216.95404
105 Low 330042.631 69774.392944 260268.23805
;
Run;
data have_neg;
set have;
area_under = -1 * area_under;
run;
proc format;
proc format;
picture posval low-high='000,009';
run;
proc sgplot data=have;
yaxis label="Area";
vbar co2 / response=area_under stat=mean limitstat=stddev discreteoffset=-0.2 barwidth=0.4;
vbar co2 / response=area_over stat=mean limitstat=stddev discreteoffset=0.2 barwidth=0.4;
run;
proc sgplot data=have_neg;
format area_under posval.;
xaxis label="Area";
hbar co2 / response=area_under stat=mean;
hbar co2 / response=area_over stat=mean;
run;
Hope this helps!
Dan
Where do the 0 and 1 come from for the first graph???
It looks like as at least one step you need something like:
data have; input ID $ co2 $ area area_under area_over; under = area_under/area; over = area_over /area; datalines; 101 High 329274.45563 1161.4533333 328113.0023 101 Low 329807.07976 51867.348667 277939.7311 103 High 299940.79867 1437.205 298503.59367 103 Low 309707.27464 196061.47517 113645.79948 105 High 500296.11766 32079.163619 468216.95404 105 Low 330042.631 69774.392944 260268.23805 ; Run;
(Note: the semicolon to end a datalines block must be after the last line of data)
Or perhaps you intend to sum the area, area_under and area_over and then do the percentages. But I can't tell which.
Try the following and see if they meet your needs:
data have;
input ID $ co2 $ area area_under area_over;
datalines;
101 High 329274.45563 1161.4533333 328113.0023
101 Low 329807.07976 51867.348667 277939.7311
103 High 299940.79867 1437.205 298503.59367
103 Low 309707.27464 196061.47517 113645.79948
105 High 500296.11766 32079.163619 468216.95404
105 Low 330042.631 69774.392944 260268.23805
;
Run;
data have_neg;
set have;
area_under = -1 * area_under;
run;
proc format;
proc format;
picture posval low-high='000,009';
run;
proc sgplot data=have;
yaxis label="Area";
vbar co2 / response=area_under stat=mean limitstat=stddev discreteoffset=-0.2 barwidth=0.4;
vbar co2 / response=area_over stat=mean limitstat=stddev discreteoffset=0.2 barwidth=0.4;
run;
proc sgplot data=have_neg;
format area_under posval.;
xaxis label="Area";
hbar co2 / response=area_under stat=mean;
hbar co2 / response=area_over stat=mean;
run;
Hope this helps!
Dan
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.