N/A
Posts: 0

# How to perform a random selection based on percentage

I'm creating a stored process which will produce a report of employees chosen at random, based on selected percentages. However, I am not sure of how to do this in Ent. Guide! Would I use something like the following:

proc surveyselect data=HMASelect
n=25;
method=srs
out=HSW;
run;

However, I don't want to hard-code the n=25; above....I want to be able to process my entire table.

Also, in the same program, I need to select a certain percentage of administrators, a certain percentage of staff and a certain percentage of classified employees. In short.... say 25 % of admin, 50% of staff and the remainder to be 25%. Then, for example, in the 25% of admin, to randomly select admin, and so on.

N/A
Posts: 0

## Re: How to perform a random selection based on percentage

Anybody ??? I actually only need help with how to figure the percentage pieces. I've looked at the samples under SAS Tech Support and through Google, but do not understand the percentage derivations.

Plus, the books we have on site don't cover proc surveyselect....the books are too old.

SAS Super FREQ
Posts: 8,868

## Re: How to perform a random selection based on percentage

Hi,
I was a Lit major and now I'm a report geek (and teacher). I don't use PROC SURVEYSELECT. Your best bet for help using PROC SURVEYSELECT is to contact Tech Support.
cynthia
Frequent Contributor
Posts: 91

## Re: How to perform a random selection based on percentage

"Plus, the books we have on site don't cover proc surveyselect....the books are too old."

Try
http://support.sas.com/onlinedoc/913/docMainpage.jsp
N/A
Posts: 0

## Re: How to perform a random selection based on percentage

Thanks for the link....I'll check it out.
Super Contributor
Posts: 260

## Re: How to perform a random selection based on percentage

Try the SAMPRATE=0.25 instead of the N option.
This will draw you a sample which size is one fourth of the total dataset.

Regards,
Olivier
N/A
Posts: 0

## Re: How to perform a random selection based on percentage

Oliver,

Thanks for replying, however, I need to process my whole dataset, as mentioned in my initial note:

"However, I don't want to hard-code the n=25; above....I want to be able to process my entire table.

Also, in the same program, I need to select a certain percentage of administrators, a certain percentage of staff and a certain percentage of classified employees. In short.... say 25 % of admin, 50% of staff and the remainder to be 25%. Then, for example, in the 25% of admin, to randomly select admin, and so on."

SAS Super FREQ
Posts: 8,868

## Re: How to perform a random selection based on percentage

Hi:
According to the SURVEYSELECT doc, you can
"....can perform stratified sampling, selecting samples independently within the specified strata, or nonoverlapping subgroups of the survey population. "

If reading the documentation doesn't help, then you may want to search for papers about PROC SURVEYSELECT. Or, if your data are not survey-based, you may wish to investigate other techniques to randomly select observations. Tech Support can help you figure out the best technique to use.

To send a question to Tech Support, go to http://support.sas.com/ and in the left-hand navigation pane, click on the link entitled "Submit a Problem".
cynthia
Super Contributor
Posts: 260

## Re: How to perform a random selection based on percentage

Hi SASMan.

It's just me being stupid : I misread your problem. Now that you explain (twice), I think I understand.
You can use the SAMPRATE option pointing on a dataset containing the percentage (in a variable that MUST be named _RATE_) of each subgroup you want to draw samples from.
[pre]
PROC SORT DATA = yourData OUT = work.categories NODUPKEY ;
BY status ;
RUN ;
DATA work.categories ;
SET work.categories (KEEP = status) ;
IF status = "Admin" THEN _rate_ = .25 ;
ELSE _rate_ = .50 ;
RUN ;
PROC SURVEYSELECT DATA = yourData OUT = yourSelection
METHOD = SRS NOPRINT
SAMPRATE = work.categories ;
STRATA status ; /* your dataset must be sorted by STATUS */
RUN ;
[/pre]

I hope that this time I am delivering interesting information. If not, please feel free to ask again -- in the end I may understand something :-)
Cheers,
Olivier
N/A
Posts: 0

## Re: How to perform a random selection based on percentage

Olivier,

Actually, that looks quite like what I'm thinking of! I'lltake a crack at modifying your code suggestion and see what comes out the other end.

Thank you very much! I'll let you know.....
Discussion stats
• 9 replies
• 397 views
• 0 likes
• 4 in conversation