x cd /pub/sas/formats/Tools; %let pgm=gen_mable14fmats; filename pgm "&pgm..sas"; *---We want to create alternative formats that put names to cbsa codes for specific time periods. The codes not change ane the names will. geocorr14 user pointed out that we were providing the 2013 names for the 2009 / 2010 Boston CBSA because it changed over time. For now, these new formats are stored in mable12.formats because that it what is referenced in our autoexec.web.sas module. Aug. 2015: adding 2 new formts: hrr and hsa . ---; libname georef '/pub/data/georef'; libname mable14 '/pub/data/mable14'; libname mable12 '/pub/data/mable12'; options nosource; *--We ran this code to see what had changed. More than was easy to fix manually (200+)--; %macro whatchanged; *----We shall merge the georef files for the various time periods and see what codes have changed. Then we can manually code the new format defns where we create reference to the current value as other= specs. ---; data georef.cbsa_name_changes; merge georef.cbsas09(in=in09 rename=(areaname=areaname09 cbsatype=cbsatype09 csa=csa09)) georef.cbsas13(in=in13 rename=(areaname=areaname13 cbsatype=cbsatype13 csa=csa13)) georef.cbsas15(in=in13 rename=(areaname=areaname15 cbsatype=cbsatype15 csa=csa15)) ; BY CBSA; options mprint; if in09 then do; ix=index(areaname09,'Metropolitan Statistical') ; if ix then substr(areaname09,ix)=' '; ix=index(areaname09,'Micropolitan Statistical') ; if ix then substr(areaname09,ix)=' '; end; %macro compare(yr,curyr); ( areaname&yr ne areaname&curyr ) or (cbsatype&yr ne cbsatype&curyr) /* or (csa&yr ne csa&curyr) */ %mend compare; if %compare(09,15) or %compare(13,15) then output; drop year states nstates ix; run; proc print data=georef.cbsa_name_changes(drop=csaname); run; %mend whatchanged; %macro doyr(yr); proc sort data=georef.cbsas&yr nodupkeys out=cbsasnodups&yr ; by cbsa ; run; data cbsas&yr; set cbsasnodups&yr; %if &yr=xx %then %do; ***length newname $88 ; _ix=index(cbsaname,cbsatype||'politan'); if _ix=0 then do; put / _all_; _nbad +1; if _nbad ge 5 then abort abend; end; cbsaname=substr(cbsaname,1,_ix-1)||'('||CBSATYPE||')'; _ix=index(csaname,'Combined S'); substr(csaname,_ix)=' '; drop _: ; %end; %else %do; length cbsaname $88; cbsaname=trim(areaname)||' ('||CBSATYPE||')'; drop areaname; %end; run; filename text "/pub/sas/formats/cbsa&yr._.sas" ; %genfmat(fmatname=cbsa&yr._, argvars=cbsa,arglen=5,labelvar=cbsaname,labellen=88, setin=cbsas&yr, fmatlib=mable14, runproc=1) ; proc sort data=georef.csacbsas&yr(keep=csa csaname) out=csas&yr nodupkeys; by csa; run; filename text "/pub/sas/formats/csa&yr._.sas" ; %genfmat(fmatname=csa&yr._, argvars=csa,arglen=3,labelvar=csaname,labellen=80, setin=csas&yr, fmatlib=mable14, runproc=1) ; %mend doyr; options source; options nomprint; /*<=========================Comment out===================================== %doyr(09); %doyr(13); %doyr(15); ===========================End commented out================================ */ filename texthsa "/pub/sas/formats/Shsa.sas"; filename texthrr "/pub/sas/formats/Shrr.sas"; %genfmat(fmatname=hsa,sasin=georef.hsanames,textfile=texthsa,argvars=hsa,arglen=5, labelvar=hsaname,labellen=80,fmatlib=mable14) %genfmat(fmatname=hrr,sasin=georef.hrrnames,textfile=texthrr,argvars=hrr,arglen=3, labelvar=hrrname,labellen=80,fmatlib=mable14) options fmtsearch=(work mable14 sasctlgs); data _null_; c='14460'; put c $5. +1 c $cbsa09_. c $cbsa13_.; length csa $3; csa='102'; **** put csa $3. +1 csa $csa09_. +1 c $csa13_.; hrr='009'; hsa='01001'; put hrr $hrr. hsa $hsa. ; put hrr= $hrr. +1 hsa= $hsa. ; stop; run; %include sascode (notify);