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):
A sample from my dataset:
Thank you!
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.
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.
Ooooh you are sneaky! Yes that's a great idea.
Thank you so much for your help! I will do that :).
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.