x cd /pub/data/pums2000/Tools; %let pgm=cnvtpums1; filename pgm "&pgm..sas"; *--Read the raw PUMS data file for a state, creating SAS datasets. John Blodgett, OSEDA, U. of Missouri Outreach & Extension Under a contract with the Missouri Census Data Center. April, 2003. Rev. 4-28-03 to adjust for input data being sorted by puma1 before serialno. Jan 31, 2005: rerun just the steps to redefine the state views for v9. --*; %let pumspath=%str(/pub/data/pums2000); libname pums2000 '/pub/data/pums2000'; libname user '/SAS_temp/user'; title "PUMS 1% Conversion run"; %macro doit(state,stab); /* =======================Begin comment================ *<============This is the pipe used to read the input data as downloaded from ftp2.census.gov====; filename datain pipe "unzip -p /pub/data/pums2000/zipfiles1/all_&statenm..zip pums_&state..dat" ; data pums2000.&stab.hrecs1(label="1% sample data for &stab, H rec data" sortedby=state puma1 serialno keep=serialno--finc) pums2000.&stab.precs1(label="1% sample data fpr &stab, P rec data" sortedby=state puma1 serialno keep=state puma1 serialno pnum--poverty); infile datain missover lrecl=512; %include 'read_pums1h.sas'; retain puma1 state; *--because we do not read these from the p record--; if rectype ne 'H' then do; put '***Expected H record not found...aborting... *** ' serialno= rectype= _n_= ; list; *abort abend; stop; end; output pums2000.&stab.hrecs1; if persons then do _pnumck=1 to persons; %include 'read_pums1p.sas'; if rectype ne 'P' then do; put '***Expected P record not found...aborting... *** ' serialno= rectype= _n_= ; list; *abort abend; stop; end; *----This happens all the time so not much use in checking for it. The pnum field is not in ascending order and is not always unique within household.---; *if pnum gt persons then do; *---this was originally a check to make sure pnum=_pnumck but turns out the data is not sorted by pnum within hh!--; * put "****Logic Problem reading &stab file. pnum value > persons count**** " serialno= persons= _pnumck= pnum= ; * _nerr+1; * if _nerr ge 200 then stop; *** abort abend; * end; output pums2000.&stab.precs1; end; run; *----optional but recommended: Verify sort order---------------------; data _null_; set pums2000.&stab.precs1(keep=state puma1 serialno); by state puma1 serialno; if _error_ then do; do loop=1 to 500; put '****precs1 file not sorted as assumed!!!!************ '; end; abort return 2000; end; run; ======================End comment================== */ data pums2000.&stab.1(label="View merging H and P 1% data for &stab")/view=pums2000.&stab.1; merge "&pumspath/&stab.hrecs1" "&pumspath/&stab.precs1"; by state puma1 serialno; run; *** proc contents data=pums2000.&stab.1 position; *** title2 "Contents Report for &stab View"; *** run; %mend doit; *--the dostates macro generates a series of invocations of doit, using the state fips codes to create the postal abbreviations and assigning the global var statenm--; %dostates(17 20 40,names=1); *--Illinois, Kansas and Oklahoma--; %*dostates(29,names=1); %*--the following is the equivalent of invoking dostates for just the state of mo--; %*let statenm=Missouri; %doit(29,mo) ;