DATA Step, Macro, Functions and more

Add dummy column to flag random sample from population

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 95
Accepted Solution

Add dummy column to flag random sample from population

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


Accepted Solutions
Solution
‎03-16-2017 01:59 PM
Super User
Posts: 11,343

Re: Add dummy column to flag random sample from population

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


All Replies
Solution
‎03-16-2017 01:59 PM
Super User
Posts: 11,343

Re: Add dummy column to flag random sample from population

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.

 

PROC Star
Posts: 307

Re: Add dummy column to flag random sample from population

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;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 158 views
  • 4 likes
  • 3 in conversation