BookmarkSubscribeRSS Feed
ammarhm
Lapis Lazuli | Level 10

This has to be very easy, but I am really stuck and unable to solve it easily.

Imagine having a table that looks like this:

PersonSexIntakeExerciseOutput
1FA1Z
2FB2Z
3MA1X
4MB1Z
5FB2X
6MA2Z
7FA1X
8MA1X
9MB1Z

and so on, so the first column is incremental, the other columns contain binary data

Let us say I want to produce a bar chart with three bars (the count of A in intake, the count of 1 in Exercise, the count of Z in Output)

and then another bar chart showing the same thing as the first chart but subgroubed by sex, ie for each one of the three groups (intake, exercise, output) two bars are shown beside each other, one for male and one for female sex.

SGplot dose that very easily (with the group=sex groupdisplay=cluster), but i am not sure how to get the counts of the respective groups

Is there an easy way or will I have to use a proc sql to count the A in intake, the count of 1 in Exercise, the count of Z in Output?

Regards

1 REPLY 1
arodriguez
Lapis Lazuli | Level 10

Hi,

You could use SGPANEL and draw two panels, one for SEX="M" and other to SEX="F" and group intake, or vice versa.

Other alternative could be generate a category variable with all your categories joined, such as A1Z and B2X for example and use this to plot

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 774 views
  • 0 likes
  • 2 in conversation