Really basic question here!
I have categorized my data into age groups (age5y) and want to create a vertical bar chart of the percentage of each age group that has a certain health condition (IAD, UKAD, IAS02_new, IAR02_new). These health condition variables are binary (0=no, 1=yes). The chart produced with the code below shows the percentage of the age group's frequency of having that condition out of the TOTAL number of cases in the sample instead of the percentage of those who have the condition among that age group.
I have tried changing stat to percent as well but that doesn't help.
proc sgplot data=recode;
vbar age5y / response=IAD stat=pct limitstat=clm;
run;
I am happy to change the chart type if necessary. I would also like to include confidence intervals or standard deviations.
Eventually, I would like to cluster the conditions such that I have the percentage of each condition per age group in one chart.
Thanks so much!
@cjp13 wrote:
I just posted some data below. Thank you!
I don't see any data. I see a picture of a summary table of some sort.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.
Very likely your existing data needs to be massaged but can't make a specific recommendation because I can't see any data.
Try something like this:
proc sgplot data=temp;
vbar x1 / group=age groupdisplay=cluster stat=percent;
where x1=1;
run;
When I do that, I still get a chart that reports percentage of the total number of cases of all age groups.
I would like each bar to represent the percentage of positives per age group. For example, for my <6m age group, there were 29/235 positive samples for 12.3% for IAD. IAD is the variable name (this table is from Excel). Note: there are more age groups in my age6mo variable than I have listed in the table below. It is abbreviated for brevity. I am also trying to get the 95% CI on each bar.
Age6mo | <6m | 6-11m | 12-17m | 18-23m | 24-29m | 30-35m | 36-41m | 42-47m | 48-53m | 54-59m |
N | 235 | 215 | 239 | 234 | 230 | 228 | 229 | 217 | 242 | 172 |
IAD count | 29 | 43 | 40 | 42 | 40 | 30 | 29 | 22 | 22 | 19 |
IAD percent | 12.3% | 20.0% | 18.0% | 19.7% | 23.9% | 16.2% | 15.7% | 13.8% | 12.0% | 15.1% |
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.