Hi, I'm trying to create a group in a proc template using this preset template. I know in sgplot you can do a by group, how would I go about creating a by group in proc template?
This is my code:
proc template;
/* Create custom style MYDEFAULT from STYLES.DEFAULT. */
define statgraph fixnew;
dynamic Cellhead;
begingraph / datacolors = (red red red red red red red) datacontrastcolors =
(red red red red red red red) ;
;
entrytitle Cellhead;
legenditem type=marker name="newitem1" / label="Mean" LABELATTRS = (color=black size=10pt) markerattrs=(symbol=diamond color=black size=9pt ) ;
layout overlay /
yaxisopts=(griddisplay=on label= "Yaxis" labelattrs=(size=9pt weight=bold)
gridattrs=(color=lightgray pattern=dot )
linearopts = (tickvaluesequence = (start = 0 end = 60 increment = 10) viewmin = 0 viewmax =60) tickvalueattrs=(size = 9pt weight=bold))
xaxisopts=(display=(tickvalues) tickvalueattrs=(size = 9pt weight=bold))
;
boxplot x = avisit y = aval_geo/ extreme=true Display =(caps mean median outliers fill ) connect=max fillattrs=(color=red); /***negative**/
boxplot x = avisit y = aval_geo/ extreme=true Display =(caps mean median outliers fill ) connect=max fillattrs=(color=blue); /***positive**/
discretelegend "newitem1" / location = outside halign =left valign=bottom
order=rowmajor across=1;
endlayout;
endgraph;
end;
run ;
For example: if the data looked like
Avisit | Aval_geo | Group |
Baseline | 0.4 | Positive |
Baseline | 0.5 | Positive |
Baseline | 10 | Negative |
Baseline | 20 | Negative |
Week 1 | 15 | Positive |
Week 1 | 10 | Positive |
Week 1 | 20 | Negative |
Week 1 | 25 | Negative |
How do I place them right next to one another in the x-axis in proc template, how would I create a group statement?
How sure are you that you actually need a custom template?
I would suggest starting with Proc Sgpanel with your Group variable as a PANELBY variable.
An example with a data set you should have access to creating two VBOX plots side by side and coloring them differently.
proc sgpanel data=sashelp.class; styleattrs datacolors= (pink blue) datacontrastcolors = (pink blue) ; panelby sex / columns=2; vbox height /group=sex; run;
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.