Programming the statistical procedures from SAS

How to get percentages?

Reply
New Contributor
Posts: 4

How to get percentages?

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?

Trusted Advisor
Posts: 2,114

How to get percentages?

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

SAS Super FREQ
Posts: 3,547

Re: How to get percentages?

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

New Contributor
Posts: 4

How to get percentages?

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

SAS Super FREQ
Posts: 3,547

How to get percentages?

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

New Contributor
Posts: 4

How to get percentages?

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

SAS Super FREQ
Posts: 3,547

How to get percentages?

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?

New Contributor
Posts: 4

How to get percentages?

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;

SAS Super FREQ
Posts: 3,547

How to get percentages?

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

Super User
Posts: 18,580

How to get percentages?

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;

Ask a Question
Discussion stats
  • 9 replies
  • 188 views
  • 0 likes
  • 4 in conversation