x cd /pub/data/sf12010/Tools; %let pgm=idfields_by_sumlev; filename pgm "&pgm..sas"; *---Examine the id (character type) variables on sf1 state level data set to see which ones are ever defined by Summary Level. We create sf1.&pgm and an html report of the same name. Per request from D. Hopkins of USDA. Aug. 2011. ---; libname user '/SAS_temp/user'; libname sf12010 '/pub/data/sf12010'; title "&pgm.: Data Set Shows Which ID Variables are Defined for What Geographic Summary Levels on State Level SF1 2010 Data Sets"; ods html file="../Idfields_by_Summary_level.html"; /* ========================begin comment==================================== proc sort data=sf12010.cainventory(keep=_character_) out=inventory nodupkeys; by sumlev; run; proc sort data=sf12010.cahierarchal(keep=_character_) out=hierarchal nodupkeys; by sumlev; run; ==========================end comment====================================== */ proc sort data=sf12010.akinventory(keep=_character_) out=inventory2 nodupkeys; by sumlev; run; proc sort data=sf12010.akhierarchal(keep=_character_) out=hierarchal2 nodupkeys; by sumlev; run; data ; set inventory hierarchal inventory2 hierarchal2 sf12010.cabgs150(keep=_character_ obs=1) sf12010.cablocks(keep=_character_ obs=1) ; by SumLev; if first.sumlev; array idvars(*) _character_; length idvariable $32 ; do i=1 to dim(idvars); idvariable=lowcase(vname(idvars(i))); if idvars(i) ne ' ' and not (idvariable in('sumlev', 'areaname') ) then do; **defined=1; output; end; end; keep sumlev idvariable; *** defined; run; proc sort out=sorted nodupkeys; by idvariable sumlev; run; data sf12010.&pgm(label='Metadata showing what SumLevs pertain to each ID variable'); set sorted; by idvariable sumlev; retain Summary_Levels; length NSumLevs 4 Summary_Levels $300; if first.idvariable then do; NSumLevs=0; Summary_levels=' '; end; Summary_Levels=catx(' ',Summary_Levels, sumlev); NSumLevs+1; if last.idvariable then output; keep idvariable NSumLevs Summary_levels; run; proc print data=sf12010.&pgm; id idvariable; run; ods html close; run;