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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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

2 REPLIES 2
ballardw
Super User
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;
Patrick
Opal | Level 21

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.

  

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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