hi,
Does someone have suggestion code to offer on how I can assign a dummy variable (1 or 0) to identify a random sample from a population?
Say I have a population of 1,800 records and I want to flag exactly 35, randomly. The random sample volume will always remain the same. I want to retain the full 1,800 records, but with a column that can be filtered to, say, 1, to identify the random sample.
Thank you
Use the right procedure and this gets easy:
proc surveyselect data=yourdatasetgoeshere out=selected outall sampsize=35; run;
The OUTALL option says to output all records from input dataset and add a variable named SELECTED which has values 0/1 with 1 indicating those selected.
Use the right procedure and this gets easy:
proc surveyselect data=yourdatasetgoeshere out=selected outall sampsize=35; run;
The OUTALL option says to output all records from input dataset and add a variable named SELECTED which has values 0/1 with 1 indicating those selected.
Here's a simple example using surveyselect (just 50 for the example). If you have the sort order the same on the frame and use the same seed, you'll keep the same sampled IDs every time you run it.
data frame;
do id = 1 to 50;
output;
end;
run;
proc surveyselect data = frame
method = srs
n = 35
out = sample outall;
run;
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.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.