BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
brulard
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

2 REPLIES 2
ballardw
Super User

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.

 

collinelliot
Barite | Level 11

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;

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!

How to Concatenate Values

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.

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