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!
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.
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;
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.
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.
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.