Program ran01.sas
options linesize=72 pagesize=60 nocenter
missing='.';
/*sample program to select one replicate per individual*/
/*you can select the first replicate, the last replicate or*/
/*a random replicate using pseudorandom numbers*/
/*coded by rf rockwell - 01/15/97*/
/*create a data file containing several records for some cws
numbers*/
data test;
input cws 1-3 day 5 tarsus 7-8;
cards;
222 1 23
222 3 25
222 2 26
111 1 27
666 2 25
666 1 29
444 1 23
444 2 24
555 2 22
555 1 21
333 1 31
333 2 33
888 3 26
888 1 24
888 2 22
777 1 27
777 2 26
;
run;
proc print data=test;
title 'original data';
run;
/*sort the data by cws and day within cws*/
proc sort data=test;
by cws day;
run;
proc print data=test;
title 'data sorted by cws and day';
run;
/*-------------------------------------------------------------------------------*/
/*select the first replicate for each cws*/
data test2;
set test;
by cws day;
if first.cws;
run;
proc print data=test2;
title 'data with first replicate only';
run;
/*-------------------------------------------------------------------------------*/
/*select the last replicate for each cws*/
data test3;
set test;
by cws day;
if last.cws;
run;
proc print data=test3;
title 'data with last replicate only';
run;
/*-------------------------------------------------------------------------------*/
/*select a random replicate for each cws*/
/*first create a random number for each replicate using a random
number generator*/
/*987654321 is an initial seed. change to get different string of
numbers*/
/*use a negative number to use the cloack as the initial seed*/
data test;
set test;
retain seed1 987654321;
call ranuni(seed1,choice);
run;
proc print data=test;
title 'original data with random variable choice';
var cws day tarsus choice;
run;
/*sort the data by cws and the random number within choice*/
proc sort data=test;
by cws choice;
run;
proc print data=test;
title 'original data sorted by cws and random number';
var cws day tarsus choice;
run;
data test4;
set test;
by cws choice;
if first.cws;
run;
proc print data=test4;
title 'data with random replicate';
var cws day tarsus choice;
updated 02/04/2000