options
mprintsymbolgen mlogic
;
%macro ransample_data(dsin,dsout,Replacement,SampleSize);
%if %upcase("&Replacement")="YES" %then%do;
%*creating random sample with replacement;
data &dsout(drop=i);
do i=1to &SampleSize;
PickIt=ceil(ranuni(123)*TotObs);
ObsPicked=PickIt;
set &dsin point=PickIt nobs=TotObs;
output;
end;
stop;
run;
%end;
%else %if %upcase("&Replacement")="NO" %then%do;
%* create random sample without replace;
data &dsout(drop=SampleSize ObsLeft);
SampleSize=&SampleSize;
ObsLeft=TotObs;
do while(SampleSize>0and ObsLeft>0) ;
PickIt+1;
if ranuni(123)<SampleSize/ObsLeft then
do;
ObsPicked=PickIt;
set &dsin point=PickIt nobs=TotObs;
output;
SampleSize=SampleSize-1;
end;
ObsLeft=ObsLeft-1;
end;
stop;
run;
%end;
%else %putERROR:Replacement shout be yes or no ;
%mendransample_data;
%ransample_data(sashelp.class, class_data_rep,yes,10);
%ransample_data(sashelp.class, class_data_norep,no,10);
%ransample_data(sashelp.class, class_data_norep,whatever,10);
|