|
Convert DBF files to SAS Datasets for PC 6.04 SAS
/*
This datastep is taken from the SUGI 18 Proceedings
page 915. It will only work with dBase III and III+ files.
This is sample code and is not supported by SAS Institute.
*/
%let fname="c:\test.dbf";
%let dsname="test";
filename dbfile &fname;
filename pinc 'pinc.sas';
options source2;
data _null_;
infile dbfile unbuffered recfm=n;
length varname $ 8 hedfmt infmt $ 9 droplist $ 200;
input @1 has_memo ib1.
@2 dbyear ib1.
@3 dbmon ib1.
@4 dbday ib1.
@5 numrecs ib4.
@9 headlen ib2.
@11 reclen ib2. ;
if has_memo ne 3 then do;
put 'WARNING: The input file has a memo file associated with it!';
put 'WARNING: Data will be lost!';
end;
put dbyear= dbmon= dbday= numrecs= headlen= reclen=;
numflds=round(((headlen-34)/32),1);
put numflds=;
pos=33;
file pinc;
if headlen le 200 then do;
hdfmt='$char' || left(put(headlen,3.)) || '.;';
put 'data ' &dsname '(drop=header del);';
put 'infile "'&fname '" unbuffered recfm=u eof=eof;';
put 'input header 'hdfmt;
end;
else do;
put 'data '&dsname';';
put 'length del $ 1;';
put 'infile "' &fname '" unbuffered recfm=u eof=eof;';
put 'input';
hedfmt='$char' || '200.';
numsects=int(headlen/200)+1;
lenlast=headlen-((numsects-1)*200);
droplist='del';
do pcs=1 to numsects-1;
|