hello!
I am very new to the sas community...hopefully someone can help me out. I am trying to make a chart for a question on a 5 point scale, I want to compare how males responded to how females responded (that is the percent of males answering "1" to the percent of females answer "1"). I can get the chart - but the error bars are killing me because to get the chart to allow for subgroup comparisons I used proc freq. This is the code for the chart (forgive the clumsiness):
%Macro frequency (vari1= , vari2= , data1=, title=, n=);
ods html;
proc freq data=pneumo.final1;
table &vari1*&vari2/nopercent chisq outpct out=&data1;
run;
ods html close;
data &data1;
set &data1;
if &vari2 = . then delete;
run;
goptions device=png;
goptions noborder;
ODS LISTING CLOSE;
ODS HTML;
goptions gunit=pct htitle=2.3 htext=1.75;
axis1 label=none value=none;
axis2 label=(a=90 'Percent') order=(0 to &n by 10) minor=(number=1) offset=(0,0);
axis3 label=none offset=(4,4) split=' ';
legend1 label=none position=(top right inside) cframe=white mode=protect
shape=bar(2,1) cborder=none across=2;
title &title;
title2 h=2 '(Percentage of respondents by sex)';
proc gchart data=&data1;
vbar &vari1/discrete
type=freq freq=pct_row outside=freq
group=&vari2
space=0
gspace=5
subgroup=&vari1 /* this controls the coloring */
maxis=axis1 /* midpoint axis */
raxis=axis2 /* response/numeric axis */
gaxis=axis3 /* group axis */
autoref /* reflines at every major axis tickmark */
clipref /* put reflines behind the bars */
cref=graycc
legend=legend1
coutline=black;
run;
quit;
ODS HTML CLOSE;
ODS LISTING;
%Mend frequency;
/*by gender*/
%frequency(vari1=sex, vari2=Q1, data1=Q1sex, n=100, title="Pneumonia is a serious disease")
The code below gives me a chart with the error bars - but does not lend itself to the comparison I'm trying to make (because I am trying to compare the percent of males providing a given response to the percent of females providing a given response):
%Macro frequency1 (vari1= , vari2= , data2=, title=, n=, G=, title2=, title3=);
goptions device=png;
goptions noborder;
ODS LISTING CLOSE;
ODS HTML;
goptions gunit=pct htitle=2.5 htext=1.75;
axis1 label=none value=none;
axis2 label=(a=90 &title2) order=(0 to &n by 10) minor=(number=1) offset=(0,0);
axis3 label=none offset=(4,4) split=' ';
legend1 label=none position=(top right inside) cframe=white mode=protect
shape=bar(2,1) cborder=none across=2;
title &title;
title2 h=2 &title3;
proc gchart data=pneumo.&data2;
vbar &vari1/ discrete
type=percent &G outside=pct
group=&vari2
space=0
gspace=5
cerror=both
clm=95
subgroup=&vari1
maxis=axis1
raxis=axis2
gaxis=axis3
autoref
clipref
cref=graycc
legend=legend1
coutline=black;
run;
quit;
ODS HTML CLOSE;
ODS LISTING;
%Mend frequency1;
/*by gender*/
%frequency1(vari1=Q1, vari2=sex, data2=Q1sex, n=100, title="Pneumonia is a serious disease", title2="Percent of Respondents", title3 = " ", G=G100)
Finally this code gives me a data set with the 95% CI...I just can't turn them into error bars!!!
frequency (vari1= , vari2= , data1=, title=, n=);
ods html;
proc freq data=pneumo.final1;
table &vari2*&vari1/nopercent chisq outpct out=&data1;
run;
data Q1; set &data1;
P = PERCENT/100 ;
if sex = 1 then N = 354;
if sex = 2 then N = 508;
LB = P - ( 1.96*SQRT( P*(1-P)/N ) ) ;
level = ( 1.96*SQRT( P*(1-P)/N ));
call symput('level', put(level,best12.));
* reset lower bound to 0 if <0 ;
IF LB < 0 THEN LB = 0 ;
UB = P + ( 1.96*SQRT( P*(1-P)/N ) ) ;
* reset upper bound to 1 if >1 ;
IF UB > 1 Then UB = 1 ;
LB = ’Lower Bound’
UB = ’Upper Bound’ ;
run;
Any help would be very appreciated!!!
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.
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.