Contributor
Posts: 20

# Random Sample Question

Utilizing proc Survey select I am trying to get a random
sample of 10 records per dataset I have created.

Each data set has been created based on specific criteria.
Unfortunately we will be running qtrly and each data set will not always have
10 records to choose from and in some instances may have not data at all. How
can I update my code to select N=10 and when there are less than 10 records it
pull all available?

Within specific datasets the random sample needs to include
a Strata Variable. I would also like to have 10 records pulled total but broken
out evenly between the strata, it is currently pulling proportionally.

Super User
Posts: 13,891

## Re: Random Sample Question

One start would be to post the code currently using (or generated by EG).

Generally to select per stratum your Sampsize option has one value per stratum. If you have varying number of strata and records per strata you're going to need to 1) determine # strata per data set, 2) calculate sampsize per strata 3) determine total records and records per strata and pass parameters to surveyselect. This sounds like it may be a requirement for some macro programming.

The ALLOC option may help with some.

Contributor
Posts: 20

## Re: Random Sample Question

Below is the code in its current state.

how can it be updated that I can get an even number of strata (right now AllLOC=Prop and I am getting 9 records for one strata and 1 for the other due to source proportion. I would like even break out so in this case with N=10 it would be 5 each. The below is specific to one dataset that has enough records to choose from but some of the other datasets do not.

SORT

DATA=WORK.MMC_FHP( WHERE=(status = 'Approved') )

OUT=WORK.SORTTempTableSorted;

BY benefit_plan;

;

SURVEYSELECT DATA=WORK.SORTTempTableSorted

OUT=WORK.MMC_FHP_APPROVAL_SAMPLE

METHOD=SRS

N=10

SEED=1

NOPRINT;

STRATA benefit_plan / ALLOC=PROP;

;

;

Super User
Posts: 13,891

## Re: Random Sample Question

To get two strata with equal numbers of samples:

SURVEYSELECT DATA=WORK.SORTTempTableSorted

OUT=WORK.MMC_FHP_APPROVAL_SAMPLE

METHOD=SRS

N=(5 5)

SEED=1

NOPRINT;

STRATA benefit_plan / ;

;
run;

You may want to look at the secondary dataset option in surveyselect as you can calculate such things as the number of strata and sample per strata and get them into a data set for parameters.

Discussion stats
• 3 replies
• 477 views
• 0 likes
• 2 in conversation