BookmarkSubscribeRSS Feed
ewolin
Calcite | Level 5

(newbie here...been using SAS for just two weeks now...)

My data set has about 2M entries broken down into 2 classes where the entries must be classified into 16 gender/age groups.  I need to make histograms of about 25 variables per entry.  Each plot must overlay histograms of one of the variables for the two classes, and I need one plot for every combination of gender/age.  The problem is that sgplot will do this if I overlay two different variables, but I want to overlay one variable for two classes.

The usual solution is to widen the data so that for each original variable there are two variables in the widened data set, one for each for each of the two classes.  This may be impractical in my case, I'd have to widen the 2M entries of 25 variables into 2M entries of (25 variables) times (2 classes)  and maybe times (16 gender/age cohorts).  Or perhaps with the use of WHERE clauses in sgplot I might only have to double the number of variables.

Overlaying in this manner is simple in other statistical packages, there must be a better way in SAS!  Might it have something to do with custom templates?  Or must I widen the data set?  And if so, must I just double the number of variables (one for each class), or must I explode each variable by a factor of 32 (for each gender/age group as well)?

Thanks,

Elliott Wolin

2 REPLIES 2
Jay54
Meteorite | Level 14

Not sure I fully understand your use case, but it seems you are asking for Histogram by groups.  Also, you did not mention which release of SAS you are using.  SGPLOT can do grouped histograms with SAS 9.4M2, released Aug 5.  But since you are unlikely to have access to that release, the only way I can see is to widen your data into individual columns per group. 

See my recent blog article: New Graph Features in SAS9.4M2

See previous article on Comparative Histograms: Comparative Histograms - Graphically Speaking

ewolin
Calcite | Level 5

Thanks Sanjay, the new features in SAS9.4M2 may be exactly what I want.  Can you specify multiple variables in the GROUP= option?

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2052 views
  • 0 likes
  • 2 in conversation