Friday, April 18, 2008

Randomly Selecting a Subset of Records From a File with Out Reading the Whole File

filename in1 "c:\tests\inf1.dat" RECFM=F LRECL=1765;;
filename out1 "c:\tests\outf1.dat" RECFM=F LRECL=1765;;

data _null_;
infile in1 obs=1000;
file out1;
input @1 _FULLREC $EBCDIC1765.;
if ranuni(0) le 0.1 then
put @1 _FULLREC $EBCDIC1765.;
run;

This code actually reads only 1000 records and with in that 10% of the data is selected for outputing to the SAS data set.

No comments: