SAS Stratified Random Sample

This post was kindly contributed by AFHood Group Blog » SAS - go there to comment and to read the full post.

There are many ways to take a stratified random sample (SRS), but we find the it doesn’t always come out as expected. That was until we started using some examples we found in a paper by Diana Suhr. This is a great example of sampling with various numbers of strata.

Example #1

PROC FREQ DATA = RAWSUB;
TABLES GEND/OUT=NEWFREQ NOPRINT;

DATA NEWFREQ2 ERROR;
SET NEWFREQ;
SAMPNUM=(PERCENT * 500)/100;
_NSIZE_= ROUND(SAMP,1);
SAMPNUM=ROUND(SAMPNUM,.01);
IF _NSIZE_=0 THEN OUTPUT ERROR;
IF _NSIZE_=0 THEN DELETE;
OUTPUT NEWFREQ2;

DATA NEWFREQ3;
SET NEWFREQ2;
KEEP GEND _NSIZE_;

PROC SORT DATA = NEWFREQ3;
BY GEND;

PROC SORT DATA = RAWSUB;
BY GEND;

PROC SURVEYSELECT DATA=RAWSUB
OUT=SAMPFL
SAMPSIZE=NEWFREQ3;
STRATA GEND;
ID ID GEND;

PROC FREQ DATA = SAMPFL;
TABLES GEND/OUT=SAMPFREQ NOPRINT;

PROC PRINT DATA=SAMPFREQ;
TITLE ‘SAMPLE FREQUENCIES’;

PROC PRINT DATA = ERROR;
TITLE 'STRATA DELETED’;

PROC DELETE DATA = NEWFREQ NEWFREQ2
NEWFREQ3 SAMPFL SAMPFREQ ERROR;

 

You can view the whole paper including other examples here:

http://support.sas.com/resources/papers/proceedings09/058-2009.pdf

This post was kindly contributed by AFHood Group Blog » SAS - go there to comment and to read the full post.