8. data work.rsubset (drop=i sampsize); sampsize = 10; do i=1 to sampsize; pickit=ceil(ranuni(0)*totobs); set sashelp.shoes point=pickit nobs=totobs; output; end; stop; run ;
10. data work.rsubset (drop=obsleft sampsize); sampsize=10; obsleft=totobs; do while (sampsize > 0); pickit + 1; if ranuni(0)<sampsize/obsleft then do; set sashelp.shoes point=pickit nobs=totobs; output; sampsize=sampsize- 1 ; end; obsleft=obsleft-1; end; stop; run ;
SAS Sampling Presenting five sampling examples and five pieces of code: 1. Systematic sample from known number of observations 2. Systematic sample from unknown number of observations 3. Random sample with replacement 4. Random sample without replacement 5. Permuted blocks randomization Why am I presenting this? SAS by default reads observations on a data set sequentially 1. May make life easier to get a sample instead of going against the entire data set. Especially when you are concerned with the accuracy of the data. 2. There may be a need for sampling in your area.