BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kgrover
Calcite | Level 5

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
ChrisHemedinger
Community Manager

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;

surveyfreq.png

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

The standard error of a percentage is 

 

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

--
Paige Miller
Reeza
Super User

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

 

What did you try?

kgrover
Calcite | Level 5

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;

PaigeMiller
Diamond | Level 26

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
ChrisHemedinger
Community Manager

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;

surveyfreq.png

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
PaigeMiller
Diamond | Level 26

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
Reeza
Super User

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;
Rick_SAS
SAS Super FREQ

This might be more information than you want, but @FreelanceReinh previously wrote an excellent answer to a related question and provided a program that computes standard errors of multinomial proportions and shows how to get the proportions, std errs, and CIs from PROC FREQ (and from a simulation). I wrote a  blog post on estimating simultaneous multinomial proportions and used the computations to estimate the proportion of colors in plain M&M candies.

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1150 views
  • 3 likes
  • 5 in conversation