BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jason2020
Obsidian | Level 7

Greetings,

I have a data set of a survey, and the program below generates a stacked bar graph of the percentage of DISEASE status (3 categories) by LOCATION. However, the graph uses the percentages of the total sample, whereas I want the graph to show the column percentages, and only for diseased individuals.

I tried using WHERE statement to include only the diseased groups, but the percentages becomes wrong. Is there a way around that?

 

ods graphics on;

proc surveyfreq data=moroc6 order=formatted;

tables disease * location /col nowt nototal plots= freqplot(groupby=column twoway=stacked scale=percent);

  where disease in ("Acute" , "Chron" , "None");

cluster province;

strata region;

weight sampling_weight;

run;

ods graphics off;

 

 

Jason2020_0-1616541934735.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jason2020
Obsidian | Level 7

Actually did some research and found the solution:

 

proc surveyfreq data=moroc6 order=formatted;
tables disease * location /col nowt;
cluster province;
strata region;
weight sampling_weight;
ods output crosstabs = Table1 (keep =disease location colPercent);
run;

 

proc sgplot data=table1 (where= ((disease ="Acute" or disease ="Chron") and location ne " "));
format colpercent 6.1;
vbar location / response=colpercent group=disease;
xaxis display=(nolabel);
yaxis grid;
run;

View solution in original post

3 REPLIES 3
Watts
SAS Employee

To display column percentages (instead of overall percentages) in a stacked bar chart, you can use the SCALE=GROUPPERCENT plot-option in PROC FREQ.

proc freq data=moroc6;
   tables disease * location / plots=freqplot(scale=grouppercent twoway=stacked);
   weight sampling_weight;
run;

 

For a stacked bar chart (which doesn't display standard errors or confidence limits), you can use PROC FREQ instead of PROC SURVEYFREQ; specify the same WEIGHT statement in PROC FREQ (to produce the same estimates of frequencies and percentages that PROC SURVEYFREQ produces).

 

Yes, the column percentages (which are percentages of the column totals) will be different if you exclude the Disease='None' cases. 

Jason2020
Obsidian | Level 7

Thank you for the solution. I now can see that Proc Freq can produce a plot of column percentages (it is odd that surveyfreq couldn't). Although this is useful, it doesn't solve my other issue (i.e., select only diseased subjects, without changing the column percentages). I therefore will modify my question.

The following program will output a subset of the column percentages to a new data set (see print out below). Can someone please direct me to which procedure will make the stacked plot, preferably if you can suggest the statement that will do the task. Thanks in advance.

 

proc surveyfreq data=moroc6 order=formatted;
tables disease * location /col nowt;
cluster province;
strata region;
weight sampling_weight;
ods output crosstabs = Table1 (keep =disease location colPercent);
run;

 

proc print data=table1;
where (disease ="Acute" or disease ="Chron") and location ne " ";
format colpercent 6.1;
run;

 

Jason2020_0-1616590682893.png

 

Jason2020
Obsidian | Level 7

Actually did some research and found the solution:

 

proc surveyfreq data=moroc6 order=formatted;
tables disease * location /col nowt;
cluster province;
strata region;
weight sampling_weight;
ods output crosstabs = Table1 (keep =disease location colPercent);
run;

 

proc sgplot data=table1 (where= ((disease ="Acute" or disease ="Chron") and location ne " "));
format colpercent 6.1;
vbar location / response=colpercent group=disease;
xaxis display=(nolabel);
yaxis grid;
run;

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

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
  • 3 replies
  • 1825 views
  • 2 likes
  • 2 in conversation