BookmarkSubscribeRSS Feed
bama8
Fluorite | Level 6

Hello!

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!

 

Cheers!

 


chart_with_missing_overall.pngGraphs.gifproc freq output.JPG
2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello Anna,

 

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;
bama8
Fluorite | Level 6

Thank you FreelanceReinhard for your speedy reply! This will work perfectly!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 2 replies
  • 1987 views
  • 0 likes
  • 2 in conversation