Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Generating SE with Proc Freq

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 07-19-2018 01:34 PM
(850 views)

I am trying to get Standard error for percentage for different levels of categorical variables (such as race) by using proc freq.

I've had no difficulty getting that with proc means but nothing seems to be working with Proc Freq.

Any help would be appreciated!

Thanks,

Kiran

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I'm beyond my depth here, statistically speaking. But syntax-wise, I know that PROC SURVEYFREQ calculates Standard Error of Percentage out of the box:

```
proc surveyfreq data=sashelp.class;
tables age ;
run;
```

8 REPLIES 8

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The standard error of a percentage is

sqrt (p * (1 - p) / n)

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I've had no difficulty getting that with proc means but nothing seems to be working with Proc Freq.

What did you try?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I have tried the following statements:

proc freq data = merged12 STDERR;

tables ATTOBEVR;run;

proc freq data = merged12;

tables ATTOBEVR / cl; run;

proc freq data = merged12;

tables ATTOBEVR / std; run;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

There is no STD option in PROC FREQ. The CL option does not apply to percentage. The formula I posted earlier provides the proper way to get standard errors of percentages.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I'm beyond my depth here, statistically speaking. But syntax-wise, I know that PROC SURVEYFREQ calculates Standard Error of Percentage out of the box:

```
proc surveyfreq data=sashelp.class;
tables age ;
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I don't think those are the same thing, because those take into account the survey design somehow. At least, they don't match the calculations of the formula for standard error of a percent in the non-survey case.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

So it's a one way table. So you can calculate the percentages and the CI for them using the BINOMIAL option. Not sure how this works with more than two levels so make sure you test it.

```
proc freq data=sashelp.class ;
table sex / binomial (level='F'); *specifies Cl and boundaries for F;
run;
```

Since this is one level at a time it's definitely easier to do the hand calculations shown by @PaigeMiller

```
/*This program calculates binomial percentages and confidence limits.
Howver, this has no correction methodology so the lower bound can go below 0.
In this case a different method is needed*/
*set table name to summarize;
%let dsin=sashelp.class;
*set variable name to get percentages;
%let var = sex;
*set name of output data set;
%let dsout = Want;
*get counts of each by group and the total count;
proc sql noprint;
create table _freq as
select &var., count(*) as N
from &dsin
group by &var.;
select count(*) into :Ntotal from &dsin.;
quit;
*calculate percentages and upper/lower confidence limits;
data &dsout.;
set _freq;
Ntotal=&ntotal.;
PCT = n/Ntotal;
STD = ((PCT*(1-PCT))/NTotal)**(1/2);
UL = PCT + 1.96*STD;
LL = PCT - 1.96*STD;
run;
*remove temporary tables;
proc sql noprint;
drop table _freq;
quit;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.