x cd /pub/data/georef/Tools; %let pgm=moblks_ur6; filename pgm "&pgm..sas"; *--modeled after /home/blodgettj/projects/urpatients/urencode.sas --; *---Assign the custom 6 urban/rural categories we defined for the Jill Lutz/Sandy Rikoon group for their project with MDC (Mo Dept of Conservation) fall, 2014. ---*; %libname (georef,opts=); %libname(mable14); filename csvout "../&pgm..csv"; filename text 'text.sas'; *--create a format code we can use to look up principal places to see if they are principal cities--; data mopcs; set georef.princities13(keep=state placefp pcounty cbsa); where state='29'; ispc='1'; run; %genfmat(sasin=mopcs,argvars=state placefp,arglen=7,labelvar=ispc,labellen=1,other=0, fmatname=isincbsa,fmatlib=work) run; proc format; Value $urcat 'U1'='U1: In Ubnzd Area & in Principal City of a MSA' 'U2'='U2: In Ubnzd Area, not in Prin. City (Suburban)' 'U3'='U3: In Urban Cluster' 'R1'='R1: Rural but in Metro. Stat. Area' 'R2'='R2: Rural but in Micro Stat. Area' 'R3'='R3: Rural, not in CBSA'; run; data georef.&pgm(label="Mo blks with 6 Urban/Rural categories used for MDC study 12/2014"); length esriid $15 URcat $2; set mable14.mov( keep=county tract block cbsa cbsatype ua placefp placesc pop10 intpt:); *by county tract block; ***=== where county in ('29019','29073'); length uatype $1; if ua ne ' ' then uatype=put(ua,$uatype.); *----Here is the algorithm for assigning the U-R categories-----*; select (uatype); when('U') do; length _parg $7 pcflag 3; _parg='29'||placefp; drop _parg; *--We use the format code generated at top of program to see if this is in a principal city of a CBSA--; pcflag=put(_parg,$isincbsa1.); if pcflag then URcat='U1'; else URcat='U2'; drop pcflag; end; when('C') URcat='U3'; when(' ') do; if cbsatype="Metro" then URcat='R1'; else if cbsatype='Micro' then URcat='R2'; else URcat='R3'; *<--R3 is non-metro rural; end; end; *--select--; City=_parg; format City $place24.; label pcflag='Principal city flag'; esriid=county||trim(compress(tract,'.'))||block; run; ods html file="&pgm..html"; title "&pgm.: Create georef dataset with the 6 U-R categories"; title2 "These are Census Block Counts"; proc freq data=georef.&pgm; table URcat; format urcat $urcat.; table county*urcat; format county $mocnty16.; run; proc freq data=georef.&pgm; weight pop10; table URcat; format urcat $urcat.; table county*urcat; format county $mocnty16.; title2 "These are 2010 Population Counts"; run; ods html close; data toexport; set georef.&pgm(keep=esriid urcat pop10 intpt:); run; proc export data=toexport dbms=csv outfile=csvout replace; run;