x cd /pub/data/stf803/Tools; %let pgm=fix_marfdata; filename pgm "&pgm..sas"; *---This custom setup fixes some problems that were created during the migrate_plus setup that created the &stab.i and &stab.h datasets. Specifically, we had data from the marf2 datasets associated with inventory level summaries that should not have been. We address those here and create updated inventory summary (&stab.i) datasets. jgb, 2-6-06. ---*; title "&pgm : Fix Problems With Marf2 data for state level inventory summaries"; libname stf803 '/pub/data/stf803'; %libname(marf2); *--1980 geographic ref file. Contains basic header info from sf3 but adds lat/long and (for some levels) landarea. Also has some basic pop counts and a pci but we keep only to total pop variable, pop100. --*; libname user '/SAS_temp/userb'; %macro doit(state,stab,app=); title "&pgm: Converting and Enhancing 1980 STF3 Data -- for &statenm"; %let ucstab=%upcase(&stab); %global age_dataset; data _null_; exists=exist("stf803.&stab.ibkup"); age_dataset= not (exists); call symput("age_dataset",put(age_dataset,1.)); stop; run; %if &age_dataset %then %do; %*--use the proc datasets age statement to create the backup/input dataset--; proc datasets nolist library=stf803; age &stab.i &stab.ibkup ; quit; %end; *---We are going to create weighted averages of latitude and longitud to get values for complete places. And, we shall be aggregating landarea, which will only be available for places of 2500+ ----; proc sort data=marf2.&stab(keep=sumrylvl place fipsplac placdesc placesze latitude longitud landarea totalpop where=(sumrylvl='13' and place ne '9999')) out=&stab.places(index=(place) drop=sumrylvl) ; by place; run; %agg(setin=&stab.places,aggout=&stab.placesagg,aggby=place,aggvars=landarea latitude longitud totalpop, means=latitude longitud, mweights=totalpop, idvars=fipsplac placdesc placesze, dropvars=_lvl_ _nag_); proc datasets library=user nolist; modify &stab.placesagg; index create place; quit; proc print data=&stab.placesagg (obs=90); title2 "&stab.placesagg"; run; data stf803.&stab.i(label="Inventory summaries for &statenm (revised)" compress=binary); set stf803.&stab.ibkup; if Sumrylvl='27' then do; set &stab.placesagg key=place; *----get the enhanced place level data---; if totalpop ne t3i1 then do; put /'***We have a logic problem: totalpop does not match t3i1*** ' / geocode= t3i1= totalpop= _iorc_= place= areaname= ; abort abend; end; pop100=totalpop; fipsmcd=' '; mcd=' '; mcdccdsz=' '; end; else if Sumrylvl='33' then do; *--congresssional district summaries had garbage marf2 data which we zap here---; smsa=' '; mcd=' '; place=' '; fipsmcd=' '; fipsplac=' '; partplac=' '; sea=' '; esr=' '; doffice=' '; smsasize=' '; uatype=' '; uasize=' '; placedesc=' '; placesze=' '; mcdccdsz=' '; indsubr=' '; sfar=' '; longitud=.; latitude =.; landarea=.; pop100=t3i1; end; drop totalpop; run; %mend doit; options NOmprint; %***dostates(10,names=1) ; *---run test on Delaware only---; %dostates(n=51,names=1); %*dostates(17 18 19 20 21 22 23 24 25 26 27); %*dostates(28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46 47 48 49 50 51 53 54 55 56,names=1) ;