SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Sampling without replacement, create two data sets

Accepted Solution Solved
Reply
Super Contributor
Posts: 328
Accepted Solution

Sampling without replacement, create two data sets

I have this data set A with N=100. I want to create a data set B with N=75 through simple random sampling without replacement and the remaining 25 should be data set C.

 

Help!


Accepted Solutions
Highlighted
Solution
‎03-26-2018 08:39 PM
Respected Advisor
Posts: 4,736

Re: Sampling without replacement, create two data sets

[ Edited ]
Posted in reply to desireatem

Beginning with SAS 9.4 Proc Surveyselect allows you to directly create both data sets.

http://support.sas.com/kb/36/383.html

 

In case you haven't a SAS license which gives you access to Proc Surveyselect: There is also a data step approach possible. Just amend the code in Method 3 under this link http://support.sas.com/kb/24/722.html to write non selected rows to another table.

  

View solution in original post


All Replies
Super User
Posts: 13,583

Re: Sampling without replacement, create two data sets

Posted in reply to desireatem
proc surveyselect data=have out=sampled 
     sampsize=75 outall;
run;

will create a data set sampled with all of the records from the have set and a variable Selected to indicate whether it was selected for the 75 or not. If you want a percentage of records then use SAMPRATE instead of SAMPSIZE.

 

If you really need to split the data then a separate data step

data samp75 samp25;
  set sampled;
  if selected then output samp75;
  else output samp25;
run;
Highlighted
Solution
‎03-26-2018 08:39 PM
Respected Advisor
Posts: 4,736

Re: Sampling without replacement, create two data sets

[ Edited ]
Posted in reply to desireatem

Beginning with SAS 9.4 Proc Surveyselect allows you to directly create both data sets.

http://support.sas.com/kb/36/383.html

 

In case you haven't a SAS license which gives you access to Proc Surveyselect: There is also a data step approach possible. Just amend the code in Method 3 under this link http://support.sas.com/kb/24/722.html to write non selected rows to another table.

  

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 110 views
  • 0 likes
  • 3 in conversation