BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
amarikow57
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.




View solution in original post

4 REPLIES 4
Reeza
Super User

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.




djrisks
Barite | Level 11

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

ghosh
Barite | Level 11

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2429 views
  • 6 likes
  • 5 in conversation