Hello Everyone,
I was able to create a box plot, But I am not getting quite what I want. I am providing the code, and customization I am looking in image. Out of 3 customization one I am not sure How I can achieve it ( making the numbers horizontal) . Making the color change I am not sure where I am doing wrong, Tried multiple attempts but not working for some reason. Your inputs and ideas greatly appreciated.
/* Step 1: Create Dummy Dataset */
data dummy_data;
input Subjid $ Age_Group $ Treatment $ AVAL;
/* Numeric representation for Treatment */
if Treatment = 'DrugA' then trtn = 1;
else if Treatment = 'DrugB' then trtn = 2;
else if Treatment = 'Refer' then trtn = 3;
/* Numeric representation for Age_Group */
if Age_Group = '5-13' then agegrpn = 1;
else if Age_Group = '14-21' then agegrpn = 2;
else if Age_Group = '22-35' then agegrpn = 3;
datalines;
S01 5-13 DrugA 6000
S02 5-13 DrugA 7000
S03 5-13 DrugB 8000
S04 5-13 DrugB 9000
S05 5-13 Refer 500
S06 5-13 Refer 12000
S07 5-13 DrugA 10000
S08 5-13 DrugB 11000
S09 5-13 Refer 400
S10 14-21 DrugA 4000
S11 14-21 DrugA 5000
S12 14-21 DrugB 6000
S13 5-13 DrugB 7000
S14 14-21 Refer 1000
S15 14-21 Refer 300
S16 22-35 DrugA 8000
S17 14-21 DrugB 9000
S18 14-21 Refer 100
S19 22-35 DrugA 200
S20 22-35 DrugA 300
S21 22-35 DrugB 400
S22 22-35 DrugB 500
S23 22-35 Refer 50
S24 14-21 Refer 100
S25 22-35 DrugA 600
S26 22-35 DrugB 700
S27 22-35 Refer 150
S28 5-13 DrugA 8000
;
run;
proc sort data=dummy_data;
by trtn agegrpn;
run;
proc means data=dummy_data nway noprint;
/* by trtn strat2rn;*/
/* var pchg;*/
by trtn agegrpn;
var aval;
*output out=statall min= max= median= mean= n= q1 = q3 =/autoname;
output out=stat n=n;
run;
data final;
merge dummy_data stat(drop=_:);
by trtn agegrpn;
num =1;
run;
proc template;
define statgraph boxplot;
begingraph / datacolors=(lightblue lightgreen lightgrey) datasymbols=(trianglefilled squarefilled circlefilled);
/* Define Custom Attributes for Age Groups */
discreteattrmap name="groupline" / ignorecase=true;
value 'DrugA' / lineattrs=(color=lightblue pattern=1 thickness=2px)
markerattrs=(color=lightblue symbol=trianglefilled size=8pt)
textattrs=(color=lightblue);
value 'DrugB' / lineattrs=(color=lightgreen pattern=1 thickness=2px)
markerattrs=(color=green symbol=squarefilled size=8pt)
textattrs=(color=lightgreen);
value 'Refer' / lineattrs=(color=grey pattern=1 thickness=2px)
markerattrs=(color=grey symbol=circlefilled size=8pt)
textattrs=(color=grey);
enddiscreteattrmap;
discreteattrvar attrvar=trtgrp var=trtn attrmap='groupline';
/* Add Custom Legends */
legenditem type=markerline name='A' / lineattrs=(color=blue pattern=1 thickness=2px)
markerattrs=(color=blue size=8pt symbol=trianglefilled)
label="DrugA" labelattrs=(size=9pt);
legenditem type=markerline name='B' / lineattrs=(color=green pattern=1 thickness=2px)
markerattrs=(color=green size=8pt symbol=squarefilled)
label="DrugB" labelattrs=(size=9pt);
legenditem type=markerline name='R' / lineattrs=(color=grey pattern=1 thickness=2px)
markerattrs=(color=grey size=8pt symbol=circlefilled)
label="Refer" labelattrs=(size=9pt);
layout overlay /
xaxisopts=(offsetmin=0.12 offsetmax=0.12 label="Age Groups" labelattrs=(size=12pt weight=bold)
tickvalueattrs=(size=12pt weight=bold))
yaxisopts=(offsetmin=0.05 offsetmax=0.05 label="Results" labelfitpolicy=splitalways labelsplitchar='^'
labelattrs=(size=11pt weight=bold) tickvalueattrs=(size=12pt weight=bold)
linearopts=(tickvaluesequence=(start=-2000 end=15000 increment=1000) viewmin=-2000 viewmax=15000));
/* Reference Line */
referenceline y=0 / lineattrs=(color=grey pattern=3);
/* Box Plot */
boxplot x=agegrpn y=AVAL / group=trtn groupdisplay=cluster boxwidth=0.56 clusterwidth=0.53
medianattrs=(color=black thickness=2px);
/* Legend */
discretelegend 'A' 'B' 'R' / down=1 border=false;
/* Axis Table */
innermargin;
axistable x=agegrpn value=num / class=trtn classorder=ascending
valueattrs=(weight=bold) labelattrs=(weight=bold) colorgroup=trtgrp ;
endinnermargin;
endlayout;
endgraph;
end;
run;
proc format;
value agegrpn
1="5-13"
2="14-21"
3="22-35"
;
value treatment
1="DrugA"
2="DrugB"
3="Refer"
;
run;
/* Generate the Graph */
options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nobyline;
ods escapechar = '^';
ods results on;
ods listing close;
ods rtf file = "C:\Users\xx\test.rtf" ;
ods graphics on / imagefmt=png attrpriority=none height=4.8 in width=8.5 in border=off;
proc sgrender data=final template=boxplot;
format trtn treatment. agegrpn agegrpn.;
run;
ods rtf close;
ods listing;
"What's the reason are you using the Mean instead of the Median?"
That blue-filled triangle stands for Mean, not Median, that is reason why I used Mean.
"Can we make the median line in each box match the legend?"
Sure.Check this:
/* Step 1: Create Dummy Dataset */ data dummy_data; input Subjid $ Age_Group $ Treatment $ AVAL; /* Numeric representation for Treatment */ if Treatment = 'DrugA' then trtn = 1; else if Treatment = 'DrugB' then trtn = 2; else if Treatment = 'Refer' then trtn = 3; /* Numeric representation for Age_Group */ if Age_Group = '5-13' then agegrpn = 1; else if Age_Group = '14-21' then agegrpn = 2; else if Age_Group = '22-35' then agegrpn = 3; datalines; S01 5-13 DrugA 6000 S02 5-13 DrugA 7000 S03 5-13 DrugB 8000 S04 5-13 DrugB 9000 S05 5-13 Refer 500 S06 5-13 Refer 12000 S07 5-13 DrugA 10000 S08 5-13 DrugB 11000 S09 5-13 Refer 400 S10 14-21 DrugA 4000 S11 14-21 DrugA 5000 S12 14-21 DrugB 6000 S13 5-13 DrugB 7000 S14 14-21 Refer 1000 S15 14-21 Refer 300 S16 22-35 DrugA 8000 S17 14-21 DrugB 9000 S18 14-21 Refer 100 S19 22-35 DrugA 200 S20 22-35 DrugA 300 S21 22-35 DrugB 400 S22 22-35 DrugB 500 S23 22-35 Refer 50 S24 14-21 Refer 100 S25 22-35 DrugA 600 S26 22-35 DrugB 700 S27 22-35 Refer 150 S28 5-13 DrugA 8000 ; run; proc sort data=dummy_data; by trtn agegrpn; run; proc means data=dummy_data nway noprint; /* by trtn strat2rn;*/ /* var pchg;*/ by trtn agegrpn; var aval; *output out=statall min= max= median= mean= n= q1 = q3 =/autoname; output out=stat n=n mean=mean median=median; run; data final; merge dummy_data stat(drop=_:); by trtn agegrpn; num =1; if TREATMENT='DrugA' then do;mean1=mean;median1=median;end; if TREATMENT='DrugB' then do;mean2=mean;median2=median;end; if TREATMENT='Refer' then do;mean3=mean;median3=median;end; run; proc template; define statgraph boxplot; begingraph / datacolors=(lightblue lightgreen lightgrey) datacontrastcolors=(lightblue lightgreen lightgrey) datasymbols=(trianglefilled squarefilled circlefilled); /* Define Custom Attributes for Age Groups */ discreteattrmap name="groupline" / ignorecase=true; value 'DrugA' / lineattrs=(color=lightblue pattern=1 thickness=2px) markerattrs=(color=lightblue symbol=trianglefilled size=8pt) textattrs=(color=lightblue); value 'DrugB' / lineattrs=(color=lightgreen pattern=1 thickness=2px) markerattrs=(color=green symbol=squarefilled size=8pt) textattrs=(color=lightgreen); value 'Refer' / lineattrs=(color=grey pattern=1 thickness=2px) markerattrs=(color=grey symbol=circlefilled size=8pt) textattrs=(color=grey); enddiscreteattrmap; discreteattrvar attrvar=trtgrp var=trtn attrmap='groupline'; /* Add Custom Legends */ legenditem type=markerline name='A' / lineattrs=(color=blue pattern=1 thickness=2px) markerattrs=(color=blue size=8pt symbol=trianglefilled) label="DrugA" labelattrs=(size=9pt); legenditem type=markerline name='B' / lineattrs=(color=green pattern=1 thickness=2px) markerattrs=(color=green size=8pt symbol=squarefilled) label="DrugB" labelattrs=(size=9pt); legenditem type=markerline name='R' / lineattrs=(color=grey pattern=1 thickness=2px) markerattrs=(color=grey size=8pt symbol=circlefilled) label="Refer" labelattrs=(size=9pt); layout overlay / xaxisopts=(offsetmin=0.12 offsetmax=0.12 label="Age Groups" labelattrs=(size=12pt weight=bold) tickvalueattrs=(size=12pt weight=bold)) yaxisopts=(offsetmin=0.05 offsetmax=0.05 label="Results" labelfitpolicy=splitalways labelsplitchar='^' labelattrs=(size=11pt weight=bold) tickvalueattrs=(size=12pt weight=bold) linearopts=(tickvaluesequence=(start=-2000 end=15000 increment=1000) viewmin=-2000 viewmax=15000)); /* Reference Line */ referenceline y=0 / lineattrs=(color=grey pattern=3); /* Box Plot */ boxplot x=agegrpn y=AVAL / group=trtn groupdisplay=cluster boxwidth=0.56 clusterwidth=0.53 ; /*scatter of mean*/ scatterplot x=agegrpn y=mean1/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=trianglefilled color=blue); scatterplot x=agegrpn y=mean2/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=squarefilled color=green); scatterplot x=agegrpn y=mean3/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=circlefilled color=grey); /*scatter of median*/ highlowplot x=agegrpn low=median1 high=median1/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=blue) ; highlowplot x=agegrpn low=median2 high=median2/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=green) ; highlowplot x=agegrpn low=median3 high=median3/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=grey) ; /* Legend */ discretelegend 'A' 'B' 'R' / down=1 border=false; /* Axis Table */ innermargin; axistable x=agegrpn value=num / class=trtn classdisplay=cluster clusterwidth=0.53 classorder=ascending valueattrs=(weight=bold) labelattrs=(weight=bold) colorgroup=trtgrp ; endinnermargin; endlayout; endgraph; end; run; proc format; value agegrpn 1="5-13" 2="14-21" 3="22-35" ; value treatment 1="DrugA" 2="DrugB" 3="Refer" ; run; /* Generate the Graph */ options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nobyline; ods escapechar = '^'; ods results on; ods listing close; ods rtf file = "C:\temp\test.rtf" ; ods graphics on / imagefmt=png attrpriority=none height=4.8 in width=8.5 in border=off; proc sgrender data=final template=boxplot; format trtn treatment. agegrpn agegrpn.; run; ods rtf close; ods listing;
/* Step 1: Create Dummy Dataset */ data dummy_data; input Subjid $ Age_Group $ Treatment $ AVAL; /* Numeric representation for Treatment */ if Treatment = 'DrugA' then trtn = 1; else if Treatment = 'DrugB' then trtn = 2; else if Treatment = 'Refer' then trtn = 3; /* Numeric representation for Age_Group */ if Age_Group = '5-13' then agegrpn = 1; else if Age_Group = '14-21' then agegrpn = 2; else if Age_Group = '22-35' then agegrpn = 3; datalines; S01 5-13 DrugA 6000 S02 5-13 DrugA 7000 S03 5-13 DrugB 8000 S04 5-13 DrugB 9000 S05 5-13 Refer 500 S06 5-13 Refer 12000 S07 5-13 DrugA 10000 S08 5-13 DrugB 11000 S09 5-13 Refer 400 S10 14-21 DrugA 4000 S11 14-21 DrugA 5000 S12 14-21 DrugB 6000 S13 5-13 DrugB 7000 S14 14-21 Refer 1000 S15 14-21 Refer 300 S16 22-35 DrugA 8000 S17 14-21 DrugB 9000 S18 14-21 Refer 100 S19 22-35 DrugA 200 S20 22-35 DrugA 300 S21 22-35 DrugB 400 S22 22-35 DrugB 500 S23 22-35 Refer 50 S24 14-21 Refer 100 S25 22-35 DrugA 600 S26 22-35 DrugB 700 S27 22-35 Refer 150 S28 5-13 DrugA 8000 ; run; proc sort data=dummy_data; by trtn agegrpn; run; proc means data=dummy_data nway noprint; /* by trtn strat2rn;*/ /* var pchg;*/ by trtn agegrpn; var aval; *output out=statall min= max= median= mean= n= q1 = q3 =/autoname; output out=stat n=n mean=mean; run; data final; merge dummy_data stat(drop=_:); by trtn agegrpn; num =1; if TREATMENT='DrugA' then mean1=mean;
if TREATMENT='DrugB' then mean2=mean;
if TREATMENT='Refer' then mean3=mean;
run; proc template; define statgraph boxplot; begingraph / datacolors=(lightblue lightgreen lightgrey) datacontrastcolors=(lightblue lightgreen lightgrey) datasymbols=(trianglefilled squarefilled circlefilled); /* Define Custom Attributes for Age Groups */ discreteattrmap name="groupline" / ignorecase=true; value 'DrugA' / lineattrs=(color=lightblue pattern=1 thickness=2px) markerattrs=(color=lightblue symbol=trianglefilled size=8pt) textattrs=(color=lightblue); value 'DrugB' / lineattrs=(color=lightgreen pattern=1 thickness=2px) markerattrs=(color=green symbol=squarefilled size=8pt) textattrs=(color=lightgreen); value 'Refer' / lineattrs=(color=grey pattern=1 thickness=2px) markerattrs=(color=grey symbol=circlefilled size=8pt) textattrs=(color=grey); enddiscreteattrmap; discreteattrvar attrvar=trtgrp var=trtn attrmap='groupline'; /* Add Custom Legends */ legenditem type=markerline name='A' / lineattrs=(color=blue pattern=1 thickness=2px) markerattrs=(color=blue size=8pt symbol=trianglefilled) label="DrugA" labelattrs=(size=9pt); legenditem type=markerline name='B' / lineattrs=(color=green pattern=1 thickness=2px) markerattrs=(color=green size=8pt symbol=squarefilled) label="DrugB" labelattrs=(size=9pt); legenditem type=markerline name='R' / lineattrs=(color=grey pattern=1 thickness=2px) markerattrs=(color=grey size=8pt symbol=circlefilled) label="Refer" labelattrs=(size=9pt); layout overlay / xaxisopts=(offsetmin=0.12 offsetmax=0.12 label="Age Groups" labelattrs=(size=12pt weight=bold) tickvalueattrs=(size=12pt weight=bold)) yaxisopts=(offsetmin=0.05 offsetmax=0.05 label="Results" labelfitpolicy=splitalways labelsplitchar='^' labelattrs=(size=11pt weight=bold) tickvalueattrs=(size=12pt weight=bold) linearopts=(tickvaluesequence=(start=-2000 end=15000 increment=1000) viewmin=-2000 viewmax=15000)); /* Reference Line */ referenceline y=0 / lineattrs=(color=grey pattern=3); /* Box Plot */ boxplot x=agegrpn y=AVAL / group=trtn groupdisplay=cluster boxwidth=0.56 clusterwidth=0.53 medianattrs=(color=black thickness=2px); /*scatter of mean*/ scatterplot x=agegrpn y=mean1/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=trianglefilled color=blue); scatterplot x=agegrpn y=mean2/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=squarefilled color=green); scatterplot x=agegrpn y=mean3/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=circlefilled color=grey); /* Legend */ discretelegend 'A' 'B' 'R' / down=1 border=false; /* Axis Table */ innermargin; axistable x=agegrpn value=num / class=trtn classdisplay=cluster clusterwidth=0.53 classorder=ascending valueattrs=(weight=bold) labelattrs=(weight=bold) colorgroup=trtgrp ; endinnermargin; endlayout; endgraph; end; run; proc format; value agegrpn 1="5-13" 2="14-21" 3="22-35" ; value treatment 1="DrugA" 2="DrugB" 3="Refer" ; run; /* Generate the Graph */ options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nobyline; ods escapechar = '^'; ods results on; ods listing close; ods rtf file = "C:\temp\test.rtf" ; ods graphics on / imagefmt=png attrpriority=none height=4.8 in width=8.5 in border=off; proc sgrender data=final template=boxplot; format trtn treatment. agegrpn agegrpn.; run; ods rtf close; ods listing;
Perfect. Thank you @Ksharp . You were awesome.
Two questions:
What's the reason are you using the Mean instead of the Median?
Can we make the median line in each box match the legend? Like in this blue-filled triangle with a blue line instead of the black line.
"What's the reason are you using the Mean instead of the Median?"
That blue-filled triangle stands for Mean, not Median, that is reason why I used Mean.
"Can we make the median line in each box match the legend?"
Sure.Check this:
/* Step 1: Create Dummy Dataset */ data dummy_data; input Subjid $ Age_Group $ Treatment $ AVAL; /* Numeric representation for Treatment */ if Treatment = 'DrugA' then trtn = 1; else if Treatment = 'DrugB' then trtn = 2; else if Treatment = 'Refer' then trtn = 3; /* Numeric representation for Age_Group */ if Age_Group = '5-13' then agegrpn = 1; else if Age_Group = '14-21' then agegrpn = 2; else if Age_Group = '22-35' then agegrpn = 3; datalines; S01 5-13 DrugA 6000 S02 5-13 DrugA 7000 S03 5-13 DrugB 8000 S04 5-13 DrugB 9000 S05 5-13 Refer 500 S06 5-13 Refer 12000 S07 5-13 DrugA 10000 S08 5-13 DrugB 11000 S09 5-13 Refer 400 S10 14-21 DrugA 4000 S11 14-21 DrugA 5000 S12 14-21 DrugB 6000 S13 5-13 DrugB 7000 S14 14-21 Refer 1000 S15 14-21 Refer 300 S16 22-35 DrugA 8000 S17 14-21 DrugB 9000 S18 14-21 Refer 100 S19 22-35 DrugA 200 S20 22-35 DrugA 300 S21 22-35 DrugB 400 S22 22-35 DrugB 500 S23 22-35 Refer 50 S24 14-21 Refer 100 S25 22-35 DrugA 600 S26 22-35 DrugB 700 S27 22-35 Refer 150 S28 5-13 DrugA 8000 ; run; proc sort data=dummy_data; by trtn agegrpn; run; proc means data=dummy_data nway noprint; /* by trtn strat2rn;*/ /* var pchg;*/ by trtn agegrpn; var aval; *output out=statall min= max= median= mean= n= q1 = q3 =/autoname; output out=stat n=n mean=mean median=median; run; data final; merge dummy_data stat(drop=_:); by trtn agegrpn; num =1; if TREATMENT='DrugA' then do;mean1=mean;median1=median;end; if TREATMENT='DrugB' then do;mean2=mean;median2=median;end; if TREATMENT='Refer' then do;mean3=mean;median3=median;end; run; proc template; define statgraph boxplot; begingraph / datacolors=(lightblue lightgreen lightgrey) datacontrastcolors=(lightblue lightgreen lightgrey) datasymbols=(trianglefilled squarefilled circlefilled); /* Define Custom Attributes for Age Groups */ discreteattrmap name="groupline" / ignorecase=true; value 'DrugA' / lineattrs=(color=lightblue pattern=1 thickness=2px) markerattrs=(color=lightblue symbol=trianglefilled size=8pt) textattrs=(color=lightblue); value 'DrugB' / lineattrs=(color=lightgreen pattern=1 thickness=2px) markerattrs=(color=green symbol=squarefilled size=8pt) textattrs=(color=lightgreen); value 'Refer' / lineattrs=(color=grey pattern=1 thickness=2px) markerattrs=(color=grey symbol=circlefilled size=8pt) textattrs=(color=grey); enddiscreteattrmap; discreteattrvar attrvar=trtgrp var=trtn attrmap='groupline'; /* Add Custom Legends */ legenditem type=markerline name='A' / lineattrs=(color=blue pattern=1 thickness=2px) markerattrs=(color=blue size=8pt symbol=trianglefilled) label="DrugA" labelattrs=(size=9pt); legenditem type=markerline name='B' / lineattrs=(color=green pattern=1 thickness=2px) markerattrs=(color=green size=8pt symbol=squarefilled) label="DrugB" labelattrs=(size=9pt); legenditem type=markerline name='R' / lineattrs=(color=grey pattern=1 thickness=2px) markerattrs=(color=grey size=8pt symbol=circlefilled) label="Refer" labelattrs=(size=9pt); layout overlay / xaxisopts=(offsetmin=0.12 offsetmax=0.12 label="Age Groups" labelattrs=(size=12pt weight=bold) tickvalueattrs=(size=12pt weight=bold)) yaxisopts=(offsetmin=0.05 offsetmax=0.05 label="Results" labelfitpolicy=splitalways labelsplitchar='^' labelattrs=(size=11pt weight=bold) tickvalueattrs=(size=12pt weight=bold) linearopts=(tickvaluesequence=(start=-2000 end=15000 increment=1000) viewmin=-2000 viewmax=15000)); /* Reference Line */ referenceline y=0 / lineattrs=(color=grey pattern=3); /* Box Plot */ boxplot x=agegrpn y=AVAL / group=trtn groupdisplay=cluster boxwidth=0.56 clusterwidth=0.53 ; /*scatter of mean*/ scatterplot x=agegrpn y=mean1/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=trianglefilled color=blue); scatterplot x=agegrpn y=mean2/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=squarefilled color=green); scatterplot x=agegrpn y=mean3/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=circlefilled color=grey); /*scatter of median*/ highlowplot x=agegrpn low=median1 high=median1/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=blue) ; highlowplot x=agegrpn low=median2 high=median2/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=green) ; highlowplot x=agegrpn low=median3 high=median3/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=grey) ; /* Legend */ discretelegend 'A' 'B' 'R' / down=1 border=false; /* Axis Table */ innermargin; axistable x=agegrpn value=num / class=trtn classdisplay=cluster clusterwidth=0.53 classorder=ascending valueattrs=(weight=bold) labelattrs=(weight=bold) colorgroup=trtgrp ; endinnermargin; endlayout; endgraph; end; run; proc format; value agegrpn 1="5-13" 2="14-21" 3="22-35" ; value treatment 1="DrugA" 2="DrugB" 3="Refer" ; run; /* Generate the Graph */ options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nobyline; ods escapechar = '^'; ods results on; ods listing close; ods rtf file = "C:\temp\test.rtf" ; ods graphics on / imagefmt=png attrpriority=none height=4.8 in width=8.5 in border=off; proc sgrender data=final template=boxplot; format trtn treatment. agegrpn agegrpn.; run; ods rtf close; ods listing;
Perfect. It worked like Gem Thank you @Ksharp
Hi @Ksharp , I have a question on this figure; when you get a chance, can you please let me know? The code I provided generated the results for the Year 2009, and it exactly produced the same results in 2010 with everything same data. Is it possible to show 6 bars in each group side by side with 2009 and 2010 results to compare in one figure? example in for one Group
Sure. Post your dataset ,so can test code.
In your original dummy dataset ,there are not YEAR variable.
OK . Using the data you posted for example:
/* Step 1: Create Dummy Dataset */
data dummy_data;
input Subjid $ Age_Group $ Treatment $ AVAL;
/* Numeric representation for Treatment */
if Treatment = 'DrugA' then trtn = 1;
else if Treatment = 'DrugB' then trtn = 2;
else if Treatment = 'Refer' then trtn = 3;
/* Numeric representation for Age_Group */
if Age_Group = '5-13' then agegrpn = 1;
else if Age_Group = '14-21' then agegrpn = 2;
else if Age_Group = '22-35' then agegrpn = 3;
datalines;
S01 5-13 DrugA 6000
S02 5-13 DrugA 7000
S03 5-13 DrugB 8000
S04 5-13 DrugB 9000
S05 5-13 Refer 500
S06 5-13 Refer 12000
S07 5-13 DrugA 10000
S08 5-13 DrugB 11000
S09 5-13 Refer 400
S10 14-21 DrugA 4000
S11 14-21 DrugA 5000
S12 14-21 DrugB 6000
S13 5-13 DrugB 7000
S14 14-21 Refer 1000
S15 14-21 Refer 300
S16 22-35 DrugA 8000
S17 14-21 DrugB 9000
S18 14-21 Refer 100
S19 22-35 DrugA 200
S20 22-35 DrugA 300
S21 22-35 DrugB 400
S22 22-35 DrugB 500
S23 22-35 Refer 50
S24 14-21 Refer 100
S25 22-35 DrugA 600
S26 22-35 DrugB 700
S27 22-35 Refer 150
S28 5-13 DrugA 8000
;
run;
data dummy_data;
length treatment _treatment $ 40;
set dummy_data;
_treatment=treatment;
treatment=cats(_treatment,'2019');
output;
/* Modify for Year 2010 */
Year = 2010;
AVAL = AVAL + 1000;
treatment=cats(_treatment,'2020');
output;
run;
proc sort data=dummy_data;
by treatment agegrpn;
run;
proc means data=dummy_data nway noprint;
/* by trtn strat2rn;*/
/* var pchg;*/
by treatment agegrpn;
var aval;
*output out=statall min= max= median= mean= n= q1 = q3 =/autoname;
output out=stat n=n mean=mean median=median;
run;
data final;
merge dummy_data stat(drop=_:);
by treatment agegrpn;
num =1;
if TREATMENT='DrugA2019' then do;mean1=mean;median1=median;end;
if TREATMENT='DrugA2020' then do;mean11=mean;median11=median;end;
if TREATMENT='DrugB2019' then do;mean2=mean;median2=median;end;
if TREATMENT='DrugB2020' then do;mean22=mean;median22=median;end;
if TREATMENT='Refer2019' then do;mean3=mean;median3=median;end;
if TREATMENT='Refer2020' then do;mean33=mean;median33=median;end;
run;
proc sort data=final;by treatment;run;
proc template;
define statgraph boxplot;
begingraph /
datacolors=(lightblue lightblue lightgreen lightgreen lightgrey lightgrey)
datacontrastcolors=(lightblue lightblue lightgreen lightgreen lightgrey lightgrey)
datasymbols=(trianglefilled trianglefilled squarefilled squarefilled circlefilled circlefilled);
/* Define Custom Attributes for Age Groups */
discreteattrmap name="groupline" / ignorecase=true;
value 'DrugA' / lineattrs=(color=lightblue pattern=1 thickness=2px)
markerattrs=(color=lightblue symbol=trianglefilled size=8pt)
textattrs=(color=lightblue);
value 'DrugB' / lineattrs=(color=lightgreen pattern=1 thickness=2px)
markerattrs=(color=green symbol=squarefilled size=8pt)
textattrs=(color=lightgreen);
value 'Refer' / lineattrs=(color=grey pattern=1 thickness=2px)
markerattrs=(color=grey symbol=circlefilled size=8pt)
textattrs=(color=grey);
enddiscreteattrmap;
discreteattrvar attrvar=trtgrp var=trtn attrmap='groupline';
/* Add Custom Legends */
legenditem type=markerline name='A' / lineattrs=(color=blue pattern=1 thickness=2px)
markerattrs=(color=blue size=8pt symbol=trianglefilled)
label="DrugA" labelattrs=(size=9pt);
legenditem type=markerline name='B' / lineattrs=(color=green pattern=1 thickness=2px)
markerattrs=(color=green size=8pt symbol=squarefilled)
label="DrugB" labelattrs=(size=9pt);
legenditem type=markerline name='R' / lineattrs=(color=grey pattern=1 thickness=2px)
markerattrs=(color=grey size=8pt symbol=circlefilled)
label="Refer" labelattrs=(size=9pt);
layout overlay /
xaxisopts=(offsetmin=0.12 offsetmax=0.12 label="Age Groups" labelattrs=(size=12pt weight=bold)
tickvalueattrs=(size=12pt weight=bold))
yaxisopts=(offsetmin=0.05 offsetmax=0.05 label="Results" labelfitpolicy=splitalways labelsplitchar='^'
labelattrs=(size=11pt weight=bold) tickvalueattrs=(size=12pt weight=bold)
linearopts=(tickvaluesequence=(start=-2000 end=15000 increment=1000) viewmin=-2000 viewmax=15000));
/* Reference Line */
referenceline y=0 / lineattrs=(color=grey pattern=3);
/* Box Plot */
boxplot x=agegrpn y=AVAL / group=treatment groupdisplay=cluster boxwidth=0.56 clusterwidth=0.53 ;
/*scatter of mean*/
scatterplot x=agegrpn y=mean1/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=trianglefilled color=blue);
scatterplot x=agegrpn y=mean11/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=trianglefilled color=blue);
scatterplot x=agegrpn y=mean2/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=squarefilled color=green);
scatterplot x=agegrpn y=mean22/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=squarefilled color=green);
scatterplot x=agegrpn y=mean3/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=circlefilled color=grey);
scatterplot x=agegrpn y=mean33/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=circlefilled color=grey);
/*scatter of median*/
highlowplot x=agegrpn low=median1 high=median1/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=blue) ;
highlowplot x=agegrpn low=median11 high=median11/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=blue) ;
highlowplot x=agegrpn low=median2 high=median2/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=green) ;
highlowplot x=agegrpn low=median22 high=median22/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=green) ;
highlowplot x=agegrpn low=median3 high=median3/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=grey) ;
highlowplot x=agegrpn low=median33 high=median33/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=grey) ;
/* Legend */
discretelegend 'A' 'B' 'R' / down=1 border=false;
/* Axis Table */
innermargin;
axistable x=agegrpn value=num / class=treatment classdisplay=cluster clusterwidth=0.53 classorder=ascending
valueattrs=(weight=bold size=12) labelattrs=(weight=bold) colorgroup=trtgrp ;
endinnermargin;
endlayout;
endgraph;
end;
run;
proc format;
value agegrpn
1="5-13"
2="14-21"
3="22-35"
;
value treatment
1="DrugA"
2="DrugB"
3="Refer"
;
run;
/* Generate the Graph */
options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nobyline;
ods escapechar = '^';
ods results on;
ods listing close;
ods rtf file = "C:\temp\test.rtf" ;
ods graphics on / imagefmt=png attrpriority=none height=4.8 in width=8.5 in border=off;
proc sgrender data=final template=boxplot;
format trtn treatment. agegrpn agegrpn.;
run;
ods rtf close;
ods listing;
Thanks for your Response. I created the Dummy data with Year and Increased the AVAL for the 2010 Year. The rest of the Proc Template code is already there in the previous post. If you need anything else please let me know.
/* Step 1: Create Dummy Dataset */
data dummy_data;
input Subjid $ Age_Group $ Treatment $ AVAL;
/* Numeric representation for Treatment */
if Treatment = 'DrugA' then trtn = 1;
else if Treatment = 'DrugB' then trtn = 2;
else if Treatment = 'Refer' then trtn = 3;
/* Numeric representation for Age_Group */
if Age_Group = '5-13' then agegrpn = 1;
else if Age_Group = '14-21' then agegrpn = 2;
else if Age_Group = '22-35' then agegrpn = 3;
/* Year for original data */
Year = 2009;
datalines;
S01 5-13 DrugA 6000
S02 5-13 DrugA 7000
S03 5-13 DrugB 8000
S04 5-13 DrugB 9000
S05 5-13 Refer 500
S06 5-13 Refer 12000
S07 5-13 DrugA 10000
S08 5-13 DrugB 11000
S09 5-13 Refer 400
S10 14-21 DrugA 4000
S11 14-21 DrugA 5000
S12 14-21 DrugB 6000
S13 5-13 DrugB 7000
S14 14-21 Refer 1000
S15 14-21 Refer 300
S16 22-35 DrugA 8000
S17 14-21 DrugB 9000
S18 14-21 Refer 100
S19 22-35 DrugA 200
S20 22-35 DrugA 300
S21 22-35 DrugB 400
S22 22-35 DrugB 500
S23 22-35 Refer 50
S24 14-21 Refer 100
S25 22-35 DrugA 600
S26 22-35 DrugB 700
S27 22-35 Refer 150
S28 5-13 DrugA 8000
;
run;
data dummy_data_final;
set dummy_data;
output;
/* Modify for Year 2010 */
Year = 2010;
AVAL = AVAL + 1000;
output;
run;
My post above has been updated.
Perfect. Thank you.🙏🙏
Hi @Ksharp is this possible the x-axis table can we group together and present it once? These numbers will be same all the time.
Sure. Of course.
/* Step 1: Create Dummy Dataset */ data dummy_data; input Subjid $ Age_Group $ Treatment $ AVAL; /* Numeric representation for Treatment */ if Treatment = 'DrugA' then trtn = 1; else if Treatment = 'DrugB' then trtn = 2; else if Treatment = 'Refer' then trtn = 3; /* Numeric representation for Age_Group */ if Age_Group = '5-13' then agegrpn = 1; else if Age_Group = '14-21' then agegrpn = 2; else if Age_Group = '22-35' then agegrpn = 3; datalines; S01 5-13 DrugA 6000 S02 5-13 DrugA 7000 S03 5-13 DrugB 8000 S04 5-13 DrugB 9000 S05 5-13 Refer 500 S06 5-13 Refer 12000 S07 5-13 DrugA 10000 S08 5-13 DrugB 11000 S09 5-13 Refer 400 S10 14-21 DrugA 4000 S11 14-21 DrugA 5000 S12 14-21 DrugB 6000 S13 5-13 DrugB 7000 S14 14-21 Refer 1000 S15 14-21 Refer 300 S16 22-35 DrugA 8000 S17 14-21 DrugB 9000 S18 14-21 Refer 100 S19 22-35 DrugA 200 S20 22-35 DrugA 300 S21 22-35 DrugB 400 S22 22-35 DrugB 500 S23 22-35 Refer 50 S24 14-21 Refer 100 S25 22-35 DrugA 600 S26 22-35 DrugB 700 S27 22-35 Refer 150 S28 5-13 DrugA 8000 ; run; data dummy_data; length treatment _treatment $ 40; set dummy_data; _treatment=treatment; treatment=cats(_treatment,'2019'); output; /* Modify for Year 2010 */ Year = 2010; AVAL = AVAL + 1000; treatment=cats(_treatment,'2020'); output; run; proc sort data=dummy_data; by treatment agegrpn; run; proc means data=dummy_data nway noprint; /* by trtn strat2rn;*/ /* var pchg;*/ by treatment agegrpn; var aval; *output out=statall min= max= median= mean= n= q1 = q3 =/autoname; output out=stat n=n mean=mean median=median; run; data final; merge dummy_data stat(drop=_:); by treatment agegrpn; num =1; if TREATMENT=:'DrugA' then do;mean1=mean;median1=median;end; if TREATMENT=:'DrugB' then do;mean2=mean;median2=median;end; if TREATMENT=:'Refer' then do;mean3=mean;median3=median;end; run; proc sort data=final;by treatment;run; proc template; define statgraph boxplot; begingraph / datacolors=(lightblue lightblue lightgreen lightgreen lightgrey lightgrey) datacontrastcolors=(lightblue lightblue lightgreen lightgreen lightgrey lightgrey) datasymbols=(trianglefilled trianglefilled squarefilled squarefilled circlefilled circlefilled); /* Define Custom Attributes for Age Groups */ discreteattrmap name="groupline" / ignorecase=true; value 'DrugA' / lineattrs=(color=lightblue pattern=1 thickness=2px) markerattrs=(color=lightblue symbol=trianglefilled size=8pt) textattrs=(color=lightblue); value 'DrugB' / lineattrs=(color=lightgreen pattern=1 thickness=2px) markerattrs=(color=green symbol=squarefilled size=8pt) textattrs=(color=lightgreen); value 'Refer' / lineattrs=(color=grey pattern=1 thickness=2px) markerattrs=(color=grey symbol=circlefilled size=8pt) textattrs=(color=grey); enddiscreteattrmap; discreteattrvar attrvar=trtgrp var=trtn attrmap='groupline'; /* Add Custom Legends */ legenditem type=markerline name='A' / lineattrs=(color=blue pattern=1 thickness=2px) markerattrs=(color=blue size=8pt symbol=trianglefilled) label="DrugA" labelattrs=(size=9pt); legenditem type=markerline name='B' / lineattrs=(color=green pattern=1 thickness=2px) markerattrs=(color=green size=8pt symbol=squarefilled) label="DrugB" labelattrs=(size=9pt); legenditem type=markerline name='R' / lineattrs=(color=grey pattern=1 thickness=2px) markerattrs=(color=grey size=8pt symbol=circlefilled) label="Refer" labelattrs=(size=9pt); layout overlay / xaxisopts=(offsetmin=0.12 offsetmax=0.12 label="Age Groups" labelattrs=(size=12pt weight=bold) tickvalueattrs=(size=12pt weight=bold)) yaxisopts=(offsetmin=0.05 offsetmax=0.05 label="Results" labelfitpolicy=splitalways labelsplitchar='^' labelattrs=(size=11pt weight=bold) tickvalueattrs=(size=12pt weight=bold) linearopts=(tickvaluesequence=(start=-2000 end=15000 increment=1000) viewmin=-2000 viewmax=15000)); /* Reference Line */ referenceline y=0 / lineattrs=(color=grey pattern=3); /* Box Plot */ boxplot x=agegrpn y=AVAL / group=treatment groupdisplay=cluster boxwidth=0.56 clusterwidth=0.53 ; /*scatter of mean*/ scatterplot x=agegrpn y=mean1/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=trianglefilled color=blue); scatterplot x=agegrpn y=mean2/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=squarefilled color=green); scatterplot x=agegrpn y=mean3/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=circlefilled color=grey); /*scatter of median*/ highlowplot x=agegrpn low=median1 high=median1/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=blue) ; highlowplot x=agegrpn low=median2 high=median2/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=green) ; highlowplot x=agegrpn low=median3 high=median3/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=grey) ; /* Legend */ discretelegend 'A' 'B' 'R' / down=1 border=false; /* Axis Table */ innermargin; axistable x=agegrpn value=num / class=trtn classdisplay=cluster clusterwidth=0.53 classorder=ascending valueattrs=(weight=bold size=12) labelattrs=(weight=bold) colorgroup=trtgrp ; endinnermargin; endlayout; endgraph; end; run; proc format; value agegrpn 1="5-13" 2="14-21" 3="22-35" ; value treatment 1="DrugA" 2="DrugB" 3="Refer" ; run; /* Generate the Graph */ options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nobyline; ods escapechar = '^'; ods results on; ods listing close; ods rtf file = "C:\temp\test.rtf" ; ods graphics on / imagefmt=png attrpriority=none height=4.8 in width=8.5 in border=off; proc sgrender data=final template=boxplot; format trtn treatment. agegrpn agegrpn.; run; ods rtf close; ods listing;
You could set NUM=. when year=2010.
I think it is easy for you , isn't it ?
/* Step 1: Create Dummy Dataset */ data dummy_data; input Subjid $ Age_Group $ Treatment $ AVAL; /* Numeric representation for Treatment */ if Treatment = 'DrugA' then trtn = 1; else if Treatment = 'DrugB' then trtn = 2; else if Treatment = 'Refer' then trtn = 3; /* Numeric representation for Age_Group */ if Age_Group = '5-13' then agegrpn = 1; else if Age_Group = '14-21' then agegrpn = 2; else if Age_Group = '22-35' then agegrpn = 3; datalines; S01 5-13 DrugA 6000 S02 5-13 DrugA 7000 S03 5-13 DrugB 8000 S04 5-13 DrugB 9000 S05 5-13 Refer 500 S06 5-13 Refer 12000 S07 5-13 DrugA 10000 S08 5-13 DrugB 11000 S09 5-13 Refer 400 S10 14-21 DrugA 4000 S11 14-21 DrugA 5000 S12 14-21 DrugB 6000 S13 5-13 DrugB 7000 S14 14-21 Refer 1000 S15 14-21 Refer 300 S16 22-35 DrugA 8000 S17 14-21 DrugB 9000 S18 14-21 Refer 100 S19 22-35 DrugA 200 S20 22-35 DrugA 300 S21 22-35 DrugB 400 S22 22-35 DrugB 500 S23 22-35 Refer 50 S24 14-21 Refer 100 S25 22-35 DrugA 600 S26 22-35 DrugB 700 S27 22-35 Refer 150 S28 5-13 DrugA 8000 ; run; data dummy_data; length treatment _treatment $ 40; set dummy_data; _treatment=treatment; treatment=cats(_treatment,'2019'); output; /* Modify for Year 2010 */ Year = 2010; AVAL = AVAL + 1000; treatment=cats(_treatment,'2020'); output; run; proc sort data=dummy_data; by treatment agegrpn; run; proc means data=dummy_data nway noprint; /* by trtn strat2rn;*/ /* var pchg;*/ by treatment agegrpn; var aval; *output out=statall min= max= median= mean= n= q1 = q3 =/autoname; output out=stat n=n mean=mean median=median; run; data final; merge dummy_data stat(drop=_:); by treatment agegrpn; num =1; if TREATMENT=:'DrugA' then do;mean1=mean;median1=median;end; if TREATMENT=:'DrugB' then do;mean2=mean;median2=median;end; if TREATMENT=:'Refer' then do;mean3=mean;median3=median;end; if year=2010 then call missing(num); run; proc sort data=final;by treatment;run; proc template; define statgraph boxplot; begingraph / datacolors=(lightblue lightblue lightgreen lightgreen lightgrey lightgrey) datacontrastcolors=(lightblue lightblue lightgreen lightgreen lightgrey lightgrey) datasymbols=(trianglefilled trianglefilled squarefilled squarefilled circlefilled circlefilled); /* Define Custom Attributes for Age Groups */ discreteattrmap name="groupline" / ignorecase=true; value 'DrugA' / lineattrs=(color=lightblue pattern=1 thickness=2px) markerattrs=(color=lightblue symbol=trianglefilled size=8pt) textattrs=(color=lightblue); value 'DrugB' / lineattrs=(color=lightgreen pattern=1 thickness=2px) markerattrs=(color=green symbol=squarefilled size=8pt) textattrs=(color=lightgreen); value 'Refer' / lineattrs=(color=grey pattern=1 thickness=2px) markerattrs=(color=grey symbol=circlefilled size=8pt) textattrs=(color=grey); enddiscreteattrmap; discreteattrvar attrvar=trtgrp var=trtn attrmap='groupline'; /* Add Custom Legends */ legenditem type=markerline name='A' / lineattrs=(color=blue pattern=1 thickness=2px) markerattrs=(color=blue size=8pt symbol=trianglefilled) label="DrugA" labelattrs=(size=9pt); legenditem type=markerline name='B' / lineattrs=(color=green pattern=1 thickness=2px) markerattrs=(color=green size=8pt symbol=squarefilled) label="DrugB" labelattrs=(size=9pt); legenditem type=markerline name='R' / lineattrs=(color=grey pattern=1 thickness=2px) markerattrs=(color=grey size=8pt symbol=circlefilled) label="Refer" labelattrs=(size=9pt); layout overlay / xaxisopts=(offsetmin=0.12 offsetmax=0.12 label="Age Groups" labelattrs=(size=12pt weight=bold) tickvalueattrs=(size=12pt weight=bold)) yaxisopts=(offsetmin=0.05 offsetmax=0.05 label="Results" labelfitpolicy=splitalways labelsplitchar='^' labelattrs=(size=11pt weight=bold) tickvalueattrs=(size=12pt weight=bold) linearopts=(tickvaluesequence=(start=-2000 end=15000 increment=1000) viewmin=-2000 viewmax=15000)); /* Reference Line */ referenceline y=0 / lineattrs=(color=grey pattern=3); /* Box Plot */ boxplot x=agegrpn y=AVAL / group=treatment groupdisplay=cluster boxwidth=0.56 clusterwidth=0.53 ; /*scatter of mean*/ scatterplot x=agegrpn y=mean1/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=trianglefilled color=blue); scatterplot x=agegrpn y=mean2/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=squarefilled color=green); scatterplot x=agegrpn y=mean3/group=treatment groupdisplay=cluster clusterwidth=0.53 markerattrs=(symbol=circlefilled color=grey); /*scatter of median*/ highlowplot x=agegrpn low=median1 high=median1/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=blue) ; highlowplot x=agegrpn low=median2 high=median2/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=green) ; highlowplot x=agegrpn low=median3 high=median3/group=treatment groupdisplay=cluster clusterwidth=0.53 type=bar barwidth=0.6 outlineattrs=(thickness=2px color=grey) ; /* Legend */ discretelegend 'A' 'B' 'R' / down=1 border=false; /* Axis Table */ innermargin; axistable x=agegrpn value=num / class=trtn classdisplay=cluster clusterwidth=0.53 classorder=ascending valueattrs=(weight=bold size=12) labelattrs=(weight=bold) colorgroup=trtgrp ; endinnermargin; endlayout; endgraph; end; run; proc format; value agegrpn 1="5-13" 2="14-21" 3="22-35" ; value treatment 1="DrugA" 2="DrugB" 3="Refer" ; run; /* Generate the Graph */ options orientation = landscape errors = 2 missing = ' ' nofmterr ls = 175 validvarname = upcase nobyline; ods escapechar = '^'; ods results on; ods listing close; ods rtf file = "C:\temp\test.rtf" ; ods graphics on / imagefmt=png attrpriority=none height=4.8 in width=8.5 in border=off; proc sgrender data=final template=boxplot; format trtn treatment. agegrpn agegrpn.; run; ods rtf close; ods listing;
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.