BookmarkSubscribeRSS Feed
murugan
Calcite | Level 5

Hi All:

I am working on a logistic regression-- binary outcome. The 1 (or the event) has a sample size of 600, while the 0 (non-event) has a sample size of 8000.

How do I extract a random sample of 600 of the non-event? It seems like proc suveyselect only lets me take a random sample of all participants, not just those who fall in the non-event.

Thanks so much!

7 REPLIES 7
ballardw
Super User

On the input dataset name use the where option to select input records only for specific values. This completely subsets the data. The selection probability and weights will only work for that subset so be careful.

proc surveyselect data=lib.have (where=(eventvariable = 0)) ....

murugan
Calcite | Level 5

This code is not working. I keep getting an error message that says that my use of the where statement is incorrect.

ballardw
Super User

Post the code you're submitting

stat_sas
Ammonite | Level 13

Hi,

Seems like trying to make a dataset containing equal number of event and non-event cases. Try this to get the desired sample dataset.

data sample;

set have;

if y=1 or (y=0 and ranuni(1234)<0.075) then output;   /* Suppose y is the event variable */

run;

murugan
Calcite | Level 5

When I used the code that you suggested, I got: data set has 0 observations and 1 variable.

I am trying to make a dataset containing an equal number of event and non-event cases.

murugan
Calcite | Level 5

Thank you for all of your help! Smiley Happy

ballardw
Super User

If you had clearly stated your need earlier then STRATA in survey select with event and nonevent sample sizes specified would have worked.

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1241 views
  • 0 likes
  • 3 in conversation