SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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