BookmarkSubscribeRSS Feed
cjp13
Calcite | Level 5

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!

 

 

5 REPLIES 5
ed_sas_member
Meteorite | Level 14

Hi @cjp13 

 

Could you please provide some sample data?

Best,

cjp13
Calcite | Level 5
I just posted some data below. Thank you!
ballardw
Super User

@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.

djmangen
Obsidian | Level 7

Try something like this:

proc sgplot data=temp;
vbar x1 / group=age groupdisplay=cluster stat=percent;
where x1=1;
run;

cjp13
Calcite | Level 5

When I do that, I still get a chart that reports percentage of the total number of cases of all age groups.

Screen Shot 2020-04-22 at 10.01.33 AM.png

 

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<6m6-11m12-17m18-23m24-29m30-35m36-41m42-47m48-53m54-59m
N235215239234230228229217242172
IAD count29434042403029222219
IAD percent12.3%20.0%18.0%19.7%23.9%16.2%15.7%13.8%12.0%15.1%

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 985 views
  • 0 likes
  • 4 in conversation