- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
Here is my data I need to represent the below data into the figure:
Data:X
Row trt01 timepoint grade percent
Pain a day1,30 min mild 33.3
Pain a day1 moderate 40.2
Pain b day1,30 min moderate 24.0
Pain b day1 mild 35.0
Pain c day1,30 min moderate 44.0
Pain c day1 mild 35.0
On the x-axis I need to display three treatment groups(trt01a) with severity grade which need to be a clustered or adjacent group bar on each timepoint. Each treatment should display there severity grade. On the x-axis I want to display(key legend) grade as below figure along with I want to display treatment group with varies color option
Here is the figure which I need : Iam using SG plot procedure but somehow I was not able to generate grouped bars with treatment groups at each time point. Do I need to use any other proc procedure. Could you please help me in providing the code with an example
on X-axis key legend should be :
Pain: Grade Mild moderate Severe
Trt : a b c
I am using below SG plot Procedure to output the figure and here is the code:
proc sgplot data=x dattrmap=attrmap;
by trtn rowlbl;
vbar tptn / response=percent group=grade name="Param" barwidth=0.5 attrid=rowlbl;
vbar tptn / response=percent group=trt groupdisplay=cluster name="Param" barwidth=0.5 attrid=rowlbl;
xaxis label='Timepoints' valueattrs=(size=8) values=(0 to valuesdisplay=('Day 1 30 Min' 'Day 1 PM' 'Day 2' 'Day 3' 'Day 4' 'Day 5' 'Day 6' 'Day 7' ); *valuesformat=atpt.;* fitpolicy=rotatethin;
yaxis values=(0 to 100 by 10) label='Percentage of Subjects with Reactions' ;
keylegend "Param"/ title=&title. location=outside position=bottom across=9 sortorder=ascending;
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's one way to do it with SAS/Graph Proc Gchart, with a partial dataset I created (I'll leave it to the ODS Graphics experts to show how to do it with Proc SGplot) 🙂
data x;
infile datalines pad truncover dlm=':';
length trt01 $3 timepoint $15 grade $10;
input trt01 timepoint grade percent;
datalines;
a:day 1, 30 min:mild:34
a:day 1, 30 min:moderate:2
a:day 1, 30 min:severe:0
b:day 1, 30 min:mild:64
b:day 1, 30 min:moderate:0
b:day 1, 30 min:severe:0
c:day 1, 30 min:mild:15.0
c:day 1, 30 min:moderate:0
c:day 1, 30 min:severe:0
a:day 1, PM:mild:62
a:day 1, PM:moderate:14
a:day 1, PM:severe:0
b:day 1, PM:mild:45
b:day 1, PM:moderate:37
b:day 1, PM:severe:0
c:day 1, PM:mild:15.0
c:day 1, PM:moderate:5
c:day 1, PM:severe:0
a:day 2:mild:78
a:day 2:moderate:11
a:day 2:severe:4
b:day 2:mild:27
b:day 2:moderate:30
b:day 2:severe:0
c:day 2:mild:15.0
c:day 2:moderate:5
c:day 2:severe:0
run;
axis1 minor=none label=(angle=90 'Percentage of Subjects with Reactions');
axis2 label=none value=none;
axis3 label=none;
legend1 label=("GRADE") shape=bar(.15in,.15in) frame;
proc gchart data=x;
vbar trt01 / sumvar=percent subgroup=grade space=0
group=timepoint maxis=axis2 gaxis=axis3 legend=legend1
raxis=axis1;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's one way to do it with SAS/Graph Proc Gchart, with a partial dataset I created (I'll leave it to the ODS Graphics experts to show how to do it with Proc SGplot) 🙂
data x;
infile datalines pad truncover dlm=':';
length trt01 $3 timepoint $15 grade $10;
input trt01 timepoint grade percent;
datalines;
a:day 1, 30 min:mild:34
a:day 1, 30 min:moderate:2
a:day 1, 30 min:severe:0
b:day 1, 30 min:mild:64
b:day 1, 30 min:moderate:0
b:day 1, 30 min:severe:0
c:day 1, 30 min:mild:15.0
c:day 1, 30 min:moderate:0
c:day 1, 30 min:severe:0
a:day 1, PM:mild:62
a:day 1, PM:moderate:14
a:day 1, PM:severe:0
b:day 1, PM:mild:45
b:day 1, PM:moderate:37
b:day 1, PM:severe:0
c:day 1, PM:mild:15.0
c:day 1, PM:moderate:5
c:day 1, PM:severe:0
a:day 2:mild:78
a:day 2:moderate:11
a:day 2:severe:4
b:day 2:mild:27
b:day 2:moderate:30
b:day 2:severe:0
c:day 2:mild:15.0
c:day 2:moderate:5
c:day 2:severe:0
run;
axis1 minor=none label=(angle=90 'Percentage of Subjects with Reactions');
axis2 label=none value=none;
axis3 label=none;
legend1 label=("GRADE") shape=bar(.15in,.15in) frame;
proc gchart data=x;
vbar trt01 / sumvar=percent subgroup=grade space=0
group=timepoint maxis=axis2 gaxis=axis3 legend=legend1
raxis=axis1;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your response
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data x;
infile datalines pad truncover dlm=':';
length trt01 $3 timepoint $15 grade $10;
input trt01 timepoint grade percent;
datalines;
a:day 1, 30 min:mild:34
a:day 1, 30 min:moderate:2
a:day 1, 30 min:severe:0
b:day 1, 30 min:mild:64
b:day 1, 30 min:moderate:0
b:day 1, 30 min:severe:0
c:day 1, 30 min:mild:15.0
c:day 1, 30 min:moderate:0
c:day 1, 30 min:severe:0
a:day 1, PM:mild:62
a:day 1, PM:moderate:14
a:day 1, PM:severe:0
b:day 1, PM:mild:45
b:day 1, PM:moderate:37
b:day 1, PM:severe:0
c:day 1, PM:mild:15.0
c:day 1, PM:moderate:5
c:day 1, PM:severe:0
a:day 2:mild:78
a:day 2:moderate:11
a:day 2:severe:4
b:day 2:mild:27
b:day 2:moderate:30
b:day 2:severe:0
c:day 2:mild:15.0
c:day 2:moderate:5
c:day 2:severe:0
;
proc sgpanel data=x ;
panelby timepoint/onepanel layout=COLUMNLATTICE novarname
NOBORDER COLHEADERPOS=bottom HEADERBACKCOLOR=white NOHEADERBORDER;
vbar trt01/response=percent group=grade barwidth=1 nostatlabel;
colaxis display=none;
rowaxis values=(0 to 100 by 10) label='Percentage of Subjects with Reactions';
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
LOL - We both 'cheated' in that neither of us used Proc SGplot! 😉
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Anybody want try by PROC SGPLOT ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
SGPANEL is the right way to create this graph with cluster groups and stacked groups among the ODS graphics tools. SGPLOT does not handle this case easily. One could try to force using SGPLOT using multiple VBAR statements with DISCRETEOFFSETs, but it easier with SGPANEL (or GCHART).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It worked . Thanks alot for your help and response . I just want need one addition to the figure .. I want to display number of subjects on each bar at particular time point . I know how to display in sgplot by using datalabels but how do i need to use in sgpanel to genearte number of subjects on each bar ..
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
SGPANEL supports the DATALABEL option like SGPLOT; but, in this case, that option will not work, as the grouped bars are "stacked" (as opposed to "clustered". You have a couple of options:
- Use the SEGLABEL option to display the value in each bar segment
- Pre-summarize the data and use VBARPARM instead of VBAR. Then, you can overlay a TEXT plot to put the values on the ends of the bars
If you need more information about the latter, let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc sgpanel data=final dattrmap=attrmap ;
by rowlbl;
panelby tptn / layout=columnlattice
onepanel noborder
colheaderpos=bottom spacing=10 ;
format tptn tptf.;
vbarparm category=trtn response=percent/ group=grade displaybaseline=auto datalabel=nsubjs dataskin=pressed;;
/* vbar tptn / datalabel=nsubjs nofill;*/
format trtn trtf.;
colaxis display=(nolabel);
rowaxis values=(0 to 100 by 10) label='Percentage of Subjects with Reactions' ;
keylegend /border;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
DATALABEL will still not work due to the stacked bars. That is why you will need to add the TEXT plot. You code will look something like the following:
vbarparm category=trtn response=percent/ group=grade displaybaseline=auto dataskin=pressed;
text x=trtn y=percent text=nsubjs / position=top pad=(bottom=5px) contributeoffsets=none;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank U so much it worked . But i need some cosmetic change where I need a space between each treatment within a panel. Here is my code iam using:
proc sgpanel data=final dattrmap=attrmap ;
by rowlbl;
panelby tptn / layout=columnlattice
onepanel noborder novarname
colheaderpos=bottom spacing=10 proportional;
format tptn tptf.;
vbarparm category=trtn response=percent/ group=grade datalabel=nsubjs groupdisplay=cluster
barwidth=1.0 DATALABELFITPOLICY=NONE DATALABELATTRS=(size=9);
format trtn trtf.;
colaxis display=(nolabel);;
rowaxis values=(0 to 100 by 10) label='Percentage of Subjects with Reactions' ;
keylegend /exclude = ("PERCENT") border;
run;