SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
agille05
Fluorite | Level 6

Hi all, 

Hoping someone could give me a hand. I'm trying to add the number of observations per category (medical conditions) per group (by gender) and haven't had any luck. I've been able to add the average age, but just can't seem to get N. Here is my code: 

Proc Sgplot data=mitacs.box dattrmap=mitacs.myattrmap noautolegend;
   ODS Graphics / antialiasmax=22000;
   Format age best4.;
   Vbox age /category=cat group=gender nooutliers attrid=gen grouporder=descending whiskerattrs=(color=CX3B3B3C) lineattrs=(color=CX3B3B3C);
   Where Gender in ("Male", "Female");
   Keylegend / location=inside position=bottom;
   Xaxis display=(nolabel);
   Yaxis values=(2 to 18 by 4) minor display=(nolabel);
   xaxistable age / stat=mean class=gender classdisplay=cluster Label="Average Age" location=inside classorder=descending;
Run;

 

And here is what my boxplots look like (would just to love N under Average Age at the bottom of the table):

Untitled.png

A sample from my dataset: 

Sample.png

Thank you! 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Short answer: Add a variable that has the value of 1 to your data set whenever AGE is not missing.

Add another Xaxis table using that variable such as:

   xaxistable agen /stat=sum class=sex classdisplay=cluster Label="Age N" location=inside classorder=descending;

That way the SUM is the N of age. My variable I named Agen to sort of describe why it is there. If this comes after your existing Xaxistable it will appear below it in the graph. If you have this one before the other it would appear above it in the graph.

View solution in original post

2 REPLIES 2
ballardw
Super User

Short answer: Add a variable that has the value of 1 to your data set whenever AGE is not missing.

Add another Xaxis table using that variable such as:

   xaxistable agen /stat=sum class=sex classdisplay=cluster Label="Age N" location=inside classorder=descending;

That way the SUM is the N of age. My variable I named Agen to sort of describe why it is there. If this comes after your existing Xaxistable it will appear below it in the graph. If you have this one before the other it would appear above it in the graph.

agille05
Fluorite | Level 6

Ooooh you are sneaky! Yes that's a great idea. 

Thank you so much for your help! I will do that :).

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2071 views
  • 1 like
  • 2 in conversation