Select several mutually exclusive samples in PROC SURVEYSELECT


The REPS= (or REP=) option in PROC SURVEYSELECT takes independent samples using the same sample design, so by definition each sample is selected from the same original frame or input data set. This means duplication is possible.

You can create mutually exclusive or nonoverlapping samples using PROC SURVEYSELECT by first selecting a single sample, without replacement, with size equal to the total number of units. Then randomly divide this sample into distinct subsamples.

Example

Suppose you want to select 5 subsamples of 10 observations from the following data set of 1,000 observations:

data a;
   do x=1 to 1000;
      output;
   end;
   run;

Use PROC SURVEYSELECT to randomly select 5 subsamples × 10 observations per subsample = 50 observations. SAMPSIZE= specifies the sample size. METHOD=SRS, the default, requests a simple random sample without replacement so that no observation is selected more than once. The OUT= data set contains the selected sample. The SEED= option is specified to allow the results of this example to be reproduced.

proc surveyselect data=a out=samples method=srs sampsize=50 seed=48922 noprint;
   run; 

To randomly assign each of the selected observations to one of five subsamples, start by adding a random number to the data set using the RANUNI function. Using the same seed allows the results of this example to be reproduced.

data samples;
   set samples;
   random=ranuni(93821);
   run;

Sorting the sample by the random numbers randomizes the order of the observations.

  proc sort data=samples;
     b
y random;
     run;

Using the CEIL function and the automatic variable _N_, this DATA step creates the variable SampleID which identifies the subsample number for each observation. The data set now has the desired number of random samples, with no replication, from the original data set.

data samples;
    set samples; 
    SampleID=ceil(_n_/10);
    drop random;
    run;

The following table displays the X values contained in the five samples in side-by-side columns.