12-13-2015 01:59 PM
I am in need of some help with getting information from outpct out= from a proc freq into proc gchart.
I have mangaged to get the PCT_ROW into the gchart, but am having trouble figuring out how to output total percents from the 2way freq table to my output data set, in addition to the row percents.
I need to create a chart that looks like the attached picture, but all I can get is the first 3 of the 4 bars (see second attached picture).
I've also put my proc freq output, just for reference.
Here is my code that is successfully giving me the output dataset and the three bars...
proc format ; value age_f 30-40='30-40' 41-55='41-55' 56-high='56+'; run; proc freq data=heart_newv ; table age*smoking / OUTPCT out = bonus; where exam = 1 AND age ne . AND smoking ne .; format smoking smoking_f. age age_f.; run; goptions reset=all; *ODS RTF FILE='C:\Users\Anna\Documents\SAS\GRAPH.RTF'; PATTERN1 color=PARP; PATTERN2 color=MORP; proc gchart data=bonus; title 'Smoking Prevalence at exam 1 by age group and overall'; vbar smoking / group=age discrete SUMVAR=PCT_ROW space=3 gspace=5 raxis=axis1 maxis=axis2 gaxis=axis3; where age ne . AND smoking ne . AND smoking = 1; axis1 label = (a=90 'Percentage Smoking')order=0 to 100 by 10; axis2 label = none; axis3 label = none; format age age_f. ; run; quit; *ODS RTF CLOSE;
Thank you kindly to whomever can help with this! I just can't seem to find an easy way to get that overall percent there!
12-14-2015 08:35 AM
You could create a more suitable dataset BONUS from the CrossTabFreqs ODS output dataset and modify the PROC GCHART step accordingly.
Here is the code:
ods output CrossTabFreqs=ctf; proc freq data=heart_newv ; table age*smoking; where exam = 1 AND age ne . AND smoking ne .; format smoking smoking_f. age age_f.; run; ods output close; data bonus; length agegrp $7; set ctf; where smoking = 1; pct=coalesce(rowpercent, percent); /* get percentages into one variable */ overall=missing(age); /* overall=1 for the 'Overall' group, 0 otherwise */ if overall then agegrp='Overall'; else agegrp=put(age, age_f.); keep agegrp overall pct; run; goptions reset=all; PATTERN1 color=PARP; PATTERN2 color=MORP; proc gchart data=bonus; title 'Smoking Prevalence at exam 1 by age group and overall'; vbar agegrp / sumvar=pct subgroup=overall nolegend space=3 raxis=axis1 maxis=axis2; axis1 label = (a=90 'Percentage Smoking')order=0 to 100 by 10; axis2 label = none; run; quit;