Is there an efficient way to create either boxplots or histograms for multiple continuous variables at once? Such as a do loop or actual function? I tried to look up a loop for graphing online, but didn't find anything that translated for me.
I do not want the graphs to overlap as is happening with this code:
PROC SGPLOT data = CLEANED.Analytic_Data;
vbox ADOS2_3_CODINGE_ANXTY_C / category = ATEAM_AUTISM_YES_NO;
vbox ADOS2_3_SCORESUMM_COMPSCORE / category = ATEAM_AUTISM_YES_NO;
vbox ADOS2_3_SCORESUMM_RRBTOTAL / category = ATEAM_AUTISM_YES_NO;
vbox ADOS2_3_SCORESUMM_SATOTAL / category = ATEAM_AUTISM_YES_NO;
vbox ADOS2_3_SCORESUMM_OVERALL / category = ATEAM_AUTISM_YES_NO;
RUN;
I have about 30 more variables to graph on top of this. I'd rather not have to type out PROC SGPLOT repeatedly if possible. Furthermore, is there a way to get a select group of variables to be side-by-side in a plot (as aforementioned, the above code just overlaps the plots). That is, all variables that start with ADOS2_3 share the same axis in one plot while stratifying the ATEAM_AUTISM_YES_NO, etc.
Thank you in advance.
Reconfigure your data so you can use a BY statement instead to get individual plots?
Flip it using PROC TRANSPOSE so you have the variable names in one column and the values in a second. Then use a single SGPLOT. You can then create some custom versions using a WHERE statement.
proc sgplot data=....;
*optional where;
where variableName like 'ADOS2_3_%';
by variableName;
vbox variableValue / category = ateam_autistm_yes_no;
run;
@amarikow57 wrote:
Is there an efficient way to create either boxplots or histograms for multiple continuous variables at once? Such as a do loop or actual function? I tried to look up a loop for graphing online, but didn't find anything that translated for me.
I do not want the graphs to overlap as is happening with this code:
PROC SGPLOT data = CLEANED.Analytic_Data; vbox ADOS2_3_CODINGE_ANXTY_C / category = ATEAM_AUTISM_YES_NO; vbox ADOS2_3_SCORESUMM_COMPSCORE / category = ATEAM_AUTISM_YES_NO; vbox ADOS2_3_SCORESUMM_RRBTOTAL / category = ATEAM_AUTISM_YES_NO; vbox ADOS2_3_SCORESUMM_SATOTAL / category = ATEAM_AUTISM_YES_NO; vbox ADOS2_3_SCORESUMM_OVERALL / category = ATEAM_AUTISM_YES_NO; RUN;
I have about 30 more variables to graph on top of this. I'd rather not have to type out PROC SGPLOT repeatedly if possible. Furthermore, is there a way to get a select group of variables to be side-by-side in a plot (as aforementioned, the above code just overlaps the plots). That is, all variables that start with ADOS2_3 share the same axis in one plot while stratifying the ATEAM_AUTISM_YES_NO, etc.
Thank you in advance.
Reconfigure your data so you can use a BY statement instead to get individual plots?
Flip it using PROC TRANSPOSE so you have the variable names in one column and the values in a second. Then use a single SGPLOT. You can then create some custom versions using a WHERE statement.
proc sgplot data=....;
*optional where;
where variableName like 'ADOS2_3_%';
by variableName;
vbox variableValue / category = ateam_autistm_yes_no;
run;
@amarikow57 wrote:
Is there an efficient way to create either boxplots or histograms for multiple continuous variables at once? Such as a do loop or actual function? I tried to look up a loop for graphing online, but didn't find anything that translated for me.
I do not want the graphs to overlap as is happening with this code:
PROC SGPLOT data = CLEANED.Analytic_Data; vbox ADOS2_3_CODINGE_ANXTY_C / category = ATEAM_AUTISM_YES_NO; vbox ADOS2_3_SCORESUMM_COMPSCORE / category = ATEAM_AUTISM_YES_NO; vbox ADOS2_3_SCORESUMM_RRBTOTAL / category = ATEAM_AUTISM_YES_NO; vbox ADOS2_3_SCORESUMM_SATOTAL / category = ATEAM_AUTISM_YES_NO; vbox ADOS2_3_SCORESUMM_OVERALL / category = ATEAM_AUTISM_YES_NO; RUN;
I have about 30 more variables to graph on top of this. I'd rather not have to type out PROC SGPLOT repeatedly if possible. Furthermore, is there a way to get a select group of variables to be side-by-side in a plot (as aforementioned, the above code just overlaps the plots). That is, all variables that start with ADOS2_3 share the same axis in one plot while stratifying the ATEAM_AUTISM_YES_NO, etc.
Thank you in advance.
The macro language and a macro %DO loop will do what you want. https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=mcrolref&docsetTarget=p0r...
As Reeza said, you should reconfigure your data, so that you can use the BY Statement. That would stop you have to write so many VBOX statements.
If you want the graphs side by side (in different cells), then you should use SGPANEL, instead of SGPLOT, after you have reconfigured your data.
If you want to also express groups differently on the same cell, then you could look into GROUPDISPLAY = CLUSTER option.
Many thanks,
Kriss
Hard to give an answer without any sample data.
I would transpose the data into three columns (eg. ADOS2_3_type, ADOS2_3_val ATEAM_AUTISM_YES_NO)
and use sgpanel to display them side by side:
proc sgpanel data=mydat;
panelby ADOS2_3_type / rows=6 columns=5 ;
vbox ADOS2_3_val / category=ATEAM_AUTISM_YES_NO;
run;
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.