BookmarkSubscribeRSS Feed
VNS0
Calcite | Level 5

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?

9 REPLIES 9
Doc_Duke
Rhodochrosite | Level 12

Actually, you can get that from PROC FREQ; -- look  at the TABLES option BINOMIAL.

Rick_SAS
SAS Super FREQ

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"?

VNS0
Calcite | Level 5

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..

Rick_SAS
SAS Super FREQ

What do you get if you run PROC FREQ on the SEX variable? Do you correctly get k males and 2433-k females?

VNS0
Calcite | Level 5

When I do proc freq on sex, I find 1971 males and 2079 females.

Rick_SAS
SAS Super FREQ

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?

VNS0
Calcite | Level 5

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;

Rick_SAS
SAS Super FREQ

I already gave you the answer. I don't have any further suggestions.  Anybody else?

Reeza
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

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.

Discussion stats
  • 9 replies
  • 1468 views
  • 0 likes
  • 4 in conversation