BookmarkSubscribeRSS Feed
H4xc1ty
Fluorite | Level 6

  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.

3 REPLIES 3
ballardw
Super User

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.

H4xc1ty
Fluorite | Level 6

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.

_CLIENTTASKFILTER = status = 'Approved';

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;

;

;


_CLIENTTASKFILTER;

ballardw
Super User

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.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 1108 views
  • 0 likes
  • 2 in conversation