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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1482 views
  • 1 like
  • 2 in conversation