I have this variable tobhrd3 (stands for: How many of you have heard of electronic cigarettes?). I want to find the % and 95% CI of each category (sex, age groups, race, income, education, region, etc) that has heard of electronic cigarettes. How do I do that? Not PROC FREQ or PROC UNIVARIATE. PROC TABULATE?
Actually, you can get that from PROC FREQ; -- look at the TABLES option BINOMIAL.
I might be confused, but can't you use PROC FREQ with a BY statement? Here's what I'm thinking (data for SEX):
data a;
input tobhrd3 sex;
datalines;
1 0
0 0
0 0
0 0
0 0
1 0
0 0
1 1
1 1
1 1
0 1
0 1
;
proc format;
value MF 1='Male' 0='Female';
run;
proc freq data=a;
by sex;
format sex MF.;
tables tobhrd3 / binomial(level=1);
run;
The BINOMIAL option is described at http://support.sas.com/documentation/cdl/en/procstat/63963/HTML/default/viewer.htm#procstat_freq_a00...
It can be used only for one-way tables. Is that why you say "not PROC FREQ"?
I tried your way but I'm seeing output for just male and not female and 2 observations only. When I ran proc freq for tobhrd3 there are total of 2433 people that heard of electronic cigarettes. Something is not right..
What do you get if you run PROC FREQ on the SEX variable? Do you correctly get k males and 2433-k females?
When I do proc freq on sex, I find 1971 males and 2079 females.
It's not feasible to debug your code long distance, but
1) make sure your data are sorted by the BY group var
2) try
TABLES sex*tobhrd3;
Do you correctly get the cross tab?
it worked. it gave me the correct numbers in the table. how do I get 95% CI?
proc freq data=merged;
tables sex*tobhrd3;
run;
I already gave you the answer. I don't have any further suggestions. Anybody else?
Calculate the % in a datastep if you're not using the default sas output from binomial as mentioned by Rick.
http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval
For results similar to Ricks that might be more useful you could consider doing the following:
ods table binomialprop=sample;
proc freq data=merged;
by sex;
tables tobhrd3/binomial(level=1);
run;
data sample2;
set sample;
where name1 in ("_BIN_", "L_BIN", "U_BIN");
run;
proc transpose data=sample2 out=answer;
by sex;
var nvalue1;
id name1;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.