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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 2106 views
  • 0 likes
  • 2 in conversation