Scott Tonidandel

SAMPLING WITH REPLACEMENT 

   The following program is a SAS macro that samples with replacement individual cases from an existing data set and creates an output file that consists of multiple "resampled" data sets. Below you will find a description of the macro, the SAS code, and an example Call Statement. For more information see: Tonidandel, S, Overall, J. E., & Smith, F. (2004). Use of resampling to select among alternative error structure specifications for GLMM analyses of repeated measurements. International Journal of Methods in Psychiatric Research, 13, 24-33. 

/*****************************************************************************************/

/*                                                                                       */

/* Macro name: %RESAMP                                                                   */

/*                                                                                       */

/* Purpose: Sampling With Replacement: Using a 'population' sample, generate sets of     */

/* resampled data from the population.                                                   */

/*                                                                                       */

/* Call Statement:                                                                       */

/*                                                                                       */

/*      %RESAMP (INP=,OUTP=,SS=,DS=,SEED=);                                              */

/*                                                                                       */

/* REQUIRED parameters: none                                                             */

/*                                                                                       */

/* OPTIONAL parameters:                                                                  */

/*                                                                                       */

/*    INP= input SAS dataset containing the 'population' sample data. If a SAS           */

/*    dataset is not specified, the most recently created SAS dataset (_LAST_)           */

/*    is used as input to the macro.                                                     */

/*                                                                                       */

/*    OUTP= SAS dataset name for the output SAS dataset. If a SAS dataset is not         */

/*    specified, the output SAS dataset default is _RESAMP1_.                            */

/*                                                                                       */

/*    SS= Sample size to generate for each resampled data set.                           */

/*    Default is 200 per grp.                                                            */

/*                                                                                       */

/*    DS= Number of resampled data sets to generate. Default is 100 sets.                */

/*                                                                                       */

/*    SEED= Seed used to initiated stream of random numbers for selection of             */

/*    observations. Must be an integer < 2**31-1. If seed is <=0 then the                */

/*    clock time is used to initiate. Default is 248531.                                 */

/*                                                                                       */

/* Printed output: none                                                                  */

/*                                                                                       */

/* Output SAS dataset:                                                                   */

/*                                                                                       */

/* name specified by:                                                                    */

/*    OUTP= (unspecified, then _RESAMP1_)                                                */

/* variables:                                                                            */

/*    all variables from input SAS dataset                                               */

/*    _SET_ data set identifier, ranges from 1 to DS                                     */

/*    _ID_ number of the record within the set.                                          */

/*                                                                                       */

/*****************************************************************************************/

 

%MACRO RESAMP(INP=_LAST_,OUTP=_RESAMP1_,SS=200,DS=100,SEED=248531);

DATA &OUTP;

_PNT_=CEIL(_NOBS_*RANUNI(&SEED));

SET &INP POINT=_PNT_ NOBS=_NOBS_;

RETAIN _SET_ 1;

_ID_+1;

  IF _ID_>&SS THEN DO;

       IF _SET_=&DS THEN STOP;

    ELSE DO;

      _ID_=1; _SET_=_SET_+1;

    END;

  END;

%MEND RESAMP;

 

/****************************************************************************************/

 

 

/*EXAMPLE CALL STATEMENT*/

%RESAMP(INP=work.origdata,OUTP=work.rsmpdata,SS=300,DS=100,SEED=80732);

run;    

For comment or questions about this page contact feduncan@davidson.edu
Search Davidson
Davidson College      Davidson, North Carolina 28035       Phone (704) 894-2000