x cd /pub/data/acs2006/Tools; %let pgm=cnvt_census_to_sas; filename pgm "&pgm..sas";
 /*---
   After we create uscensusprofiles and ustabs* (with geoid),
   we need to merge these two datasets together and create our
   own mcdc dataset.
   10/10/2007 - bce
 ---*/

 *libname user '/SAS_temp/user';

 libname acs2006 '/pub/data/acs2006';
 libname profiles '/pub/data/acs2006/profiles';
 *libname basetbl '/pub/data/acs2006/basetables';
 libname libsum '/pub/data/acs2006/summary';


 options obs=max;

 proc sort data=profiles.uscensusprofiles; by geoid; run;
 proc sort data=libsum.ustabs17_20; by geoid; run;
 proc sort data=libsum.ustabs00_07; by geoid; run;
 proc sort data=libsum.ustabs09_16; by geoid; run;
 proc sort data=libsum.ustabs25_26; by geoid; run;


 * merge uscensusprofiles and summary data sets together;


 data merged1;
 merge profiles.uscensusprofiles(in=x)
libsum.ustabs00_07(rename=(sumlev=SUM1_sumlev areaname=SUM1_areaname logrecno=SUM1_logrecno))
libsum.ustabs09_16(rename=(sumlev=SUM4_sumlev areaname=SUM4_areaname logrecno=SUM4_logrecno))
libsum.ustabs17_20(rename=(sumlev=SUM2_sumlev areaname=SUM2_areaname logrecno=SUM2_logrecno))
libsum.ustabs25_26(rename=(sumlev=SUM3_sumlev areaname=SUM3_areaname logrecno=SUM3_logrecno));
 by geoid;
 if x=1;
 run;
 

 %let dvmode=meta; %*--the "dovar mode" global parm controls what kind of output is generated by the
  dovar macro.  The values are data or meta, which cause it to either generate actual conversion data step code
  or code to create metadata set Variables.  The value is also looked at by smaller macros which generate the
  start and end of the data steps during which the dovar macro invocations take place.
 --*;

 title "&pgm: Create acs2006 profiles and profilevars datasets";

 %global pctof table curtable curtabno dvmode display;
 %let curtabno=0;
 %let display=1;
 %let REFTABLES=;
 
 %macro cnvtmeta(mode);

  %global  setin  dvmode;
  %let setout=&setin; *--by default we use the input set name base as name of output set--;
  %let dvmode=&mode;
  %if &dvmode = %str(data) %then %do;
  *---------Here is the conversion data step-------------*;
  data acs2006.usmcdcprofiles;
    length default=5; * Obs 5 esriid $16;
    set merged1;
    
    *label esriid='Id field to link to ESRI map files';

   %end;
   %else %if &dvmode=%str(meta) %then %do;
   *------Here is the data step that generate sf3x.Variables when dvmode=meta-----------;
   data acs2006.Variables(label="Meta data describing the variables on profiles datasets");
    attrib Name label='Variable Name' length=$32
     Label  length=$80 format=$char.
     Definition length=$200 label='Definition - Code used to derive'
     Comment length=$400
     Format length=$16
     TypeLen length=$8 label='Variable type and length'
     Universe length=$64
     UnivVar length=$32 label='Universe Variable'
     WtVar length=$32 label='Weight Variable'
     Lvl length=3 label="Data Indent Level"
     Display length=3 label="Display in std report?"
     PctFlag  length=3 label='Pct Variable Flag'
     Table  length=$80
     TableNo length=3 label='Table #'
     Keywords length=$80
     Year length=$4
     Source length=$40
     RefTables length=$40 label='Related Table(s)'
     ;
   retain Year '2006';
   retain Source '2006 ACS Profiles, US Census Bureau';
   %end;
   %else %put ***** dvmode parm value not recognized: value= &dvmode ;

  options NOmprint;

   %include 'invoke_dovars.sas'; %*<----this module does the work of assigning the global parms and invoking the
                 dovars parm for each variable on the dataset.  Which means this module
                 (cnvtsf3x.sas) does not really define what sf32000x is, it is this included
                 module that really does it. ----;
   %if &dvmode=%str(data) %then %do;

   keep Sumlev geoid state logrecno Areaname;
   keep TotPop -- DateCreated;
   drop _:;
   drop SUM1_:;
   drop SUM2_:;
   drop SUM3_:;
   drop SUM4_:;
   drop moe:;
   run;
   %end;

   %else %if &dvmode=%str(meta) %then %do;
    *-----meta processing-----------------------------;
    run;
    options  nonumber nodate orientation=landscape nocenter;
    ods printer pdf file="../Variables.pdf" ;  ****orient=landscape;
    ods html file='../Variables.html' contents='../VariablesContent.html' style=osedablue;
    ods listing close;
    proc print data=acs2006.Variables label;
    where pctflag=0 or UnivVar=' ';  *<--do not show the Pct variables unless they are stand-alone--;
    by table notsorted universe notsorted;
    id name;
    var label--comment UnivVar WtVar;
    format label $char.;
    title  'Metadata for the acs2006 profiles (Partial listing of Variables dataset)';
    footnote 'Note: Universe Variable is denominator used to create corresponding Pct<varname> Variable';
    title2 "Revised as of &sysdate &systime";
     run;
   ods printer close;
   ods html close;
   %end;
   %mend cnvtmeta;

  %cnvtmeta(meta) ;

  options nosource2;
  %cnvtmeta(data) ;
  run;



