/*---------------------------------------------------------------------------------------------------------- Program overview ================ (Revised, alternate version, January, 2002) Requirements ============ This code was written for SAS Version 8 or later. It uses names longer than 8 characters and labels longer than 40, which were not supported in earlier versions of SAS. Although it was written and tested on a Unix (IBM AIX) system, there is very little of the code that should be affected by platform. I.e. we expect it should run pretty much as-is in a Windows environemnt. MVS or CMS might be a little more of a challenge. In terms of computer resources, these files are quite large. You will need considerable space for storing the input files (although we try to minimize this by reading directly from zipped versions of the files). You will also need space if you are saving the output data sets. We'll publish estimates of the size requirements on a per-record basis once we have a chance to convert some larger files. Based on the test data we have to work with at the moment (mid-May, 2001) we can only say that we have tried to minimize storage by using length statements and the compress=yes option on the data sets. Changes to the new, January, 2002 version ========================================= NOTE: If you never used the earlier version you can safely ignore this section. This is for people who are trying to decide if they should switch to this new conversion approach. We decided to modify the strategy employed for storing the converted data as SAS data sets. In the original version as released in the late spring of 2001, we attempted to keep all the geographic codes separate from the tabular data. To accomplish this we created a series of "no geocodes" datasets, e.g. usphng, uspctng and uspct12Rng, and then a series of SAS views which merged these datasets with the master geocodes dataset (e.g. usgeos) to create views such as usph, uspct, and uspct12R. This strategy saved some storage space and had the advantage that we could update the geocodes dataset and have it automactically apply to the data table view sets. Another decision we made was that for a state file we would keep all the geographic summary levels on both the geos and the phng data sets. For example, mogeos and mophng would both contain data for all summary levels, including census blocks. In using the data sets over a 6-month period we discovered some serious problems with this approach. Specifically: 1. When we had occasion to update the mogeos data set, we discovered that our view files did not automatically get updated to refect the new data. We had to rerun the code that defined the view. While we had no plans to update the geos set a lot, we were disappointed to see that SAS data step views did not provide this benefit, common to most view technologies. 2. We found that access to the moph view was very slow. This was because it had to go through almost 300,000 observations to pick out the ones we wanted, even if all we were asking for was a small subset. A lot of this had to do with the fact that we kept the 279,000 or so block level summaries on the data set. Most of the time we were not interested in retrieving block level data, but we always had to slog through those to get to what we wanted. 3. We thought we could get around this problem by defining SAS data set indices on the phng data set. But it turned put that creating these actually created problems that caused the view to fail. As a result of these experiences, our new approach to the conversion is going to spend a little extra storage space as a tradeoff to get a lot better access speed when trying to retrieve observations from the table-data files/datasets. Views are abandoned; the geocodes are included with each dataset. And, block level data is kept on a separate data set. We still create a (somewhat redundant but useful) geos dataset, but it does NOT include block level data. The block geocodes are stored only on the phblks dataset. In the new scheme, for each state there are 5 datasets. For Missouri these would be: mogeos ......Geographic headers data only for all summary levels except blocks. moph..........P and H table data along with geocodes for all summary levels except blocks. mophblks......P and H table data along with geocodes for census blocks only. mopct.........PCT and HCT tables along with geocodes for all summary levels for which these data are available. mopct12R......Actually, mopct does not contain ALL PCT tables; the very detailed PCT12 race, age, sex tables are stored on this separate dataset, along with geocodes. Invoking ======== As long as nothing goes wrong, and as long as you do not want to create a custom version of the select macro, the person invoking this conversion setup should really not need to know much about SAS. Just enough to be able to point to the appropriate directories and then invoke the program. The program was debugged and tested in a batch environment. There is no user input required (or allowed) while the program is running. Typically, you will save this program in a .sas file somewhere on your system and then invoke the SAS system in batch mode, pointing to this program as the input file (after editing parameters etc as described below). Typically, it would be as simple (in Unix) as sas cnvtsf1 & You can also run the program interactively from Display Manager, of course. The nice thing about a batch invocation is that you can go away and come back later. Conversion runs for large states or on slower systems could take a while. There are over 8000 data cells for each geographic area on these data files, so there is a lot of work to be done. Inputs ====== There are 40 input files, a geographic headers/id file and 39 table cell files. All are zipped ascii files. The geography headers file is fixed format, and the remaining data segment files are all csv (comma separated value) files (though the Bureau does not use that standard extension in naming their files.) This setup reads the 39 data files using infile pipes to decompress them on the fly. We use the unzip program in the pipe. This program is compatible with pkunzip so Windows users with that program should be able to substitute pkunzip for unzip in the code. A Windows version of unzip is included in this Tools directory (as unzip.zip) which can be downloaded and used. (Alternatively, you can always go ahead and unzip all input files and alter the infile statement within the readloop macro to point to the decompressed files rather than using the pipes.) Outputs ======= The large DATA step creates 5 SAS data sets in the sf12000 data library. (The output library is expected to be permanent, so that you only have to run the conversion once, and can then access it as often as you wish. This has the advantage of being *much* faster than having to convert the raw data files each time you want to access the data. But if you prefer to reconvert each time you can easily point the sf12000 library to a temporary directory.) Each output SAS data file name begins with the state postal abbreviation, stored in the global macro variable stab. So, for example, when converting the file for New York, you would be creating the data sets: nygeos.........Geographic header and id data only (except it does contain Pop100 and HU100 total pop and HU counts). Has data fpr all geographic levels except census blocks. nyph...........Population and housing data available at all geo. levels. These are the P and H table cells. Also contains all the geographic headers variables. nyphblks.......Similar to the nyph dataset, but contains data only for census blocks. This is a HUGE dataset. Note that all the geographic header data is here (and nowhere else.) nypct..........Contains the PCT tables (except for PCT12r tables, see below), which are only available for geographic levels census tract and above. So no block group or block data here. nypct12r.......Cntains "only" the racially stratified pct12 tables, i.e., pct12a, pct12b,...,pct12o. Over 3000 data cells. Like the previous nypct set this one ontains no observations for block groups or blocks. A number of SAS indices are created on these datasets. The presumption is that the most common keys to be used for doing queires are SumLev and County, so these are the variables that we chose for indexing. Thus, for example, if you need to access block level data for a single county, you can include a where filter such as: where county='36071'; and it will go directly to the data for county 071 without having to slog through perhaps hundreds of thousands of block summaries stored in the physical dataset preceding those for county 071. Related SAS code ================ This setup references 3 other SAS source modules directly (see the "%include curpath...." statements). These 3 modules contain rather lengthy SAS LABEL statements. The code will run perfectly well if you decide you do not need these labels, in which case you can simply delete the %include statements. Otherwise you should obtain copies of these 3 modules (from the same source where you obtained this code - i.e. the same directory) and store them in the same directory as this code. The file names are phlabs.sas, pctlabs.sas, and pct12rlabs.sas . The 3 modules correspond to the 3 basic data sets created by this conversion. Not only do these sas source modules create useful variable labels that are permanently stored on your SAS datasets, but they can also be used as excellent reference files (codebooks) to help you quickly relate variable names to their meaning. We have found these files to be quite invaluable for this purpose. Note particularly, that in addition to the variable labels, they also display table titles, universes, etc. as SAS comments, which add greatly to their "codebook" value. We thank Roy Williams of the Massachussetts SDC for creating and sharing these modules with us. The $fplace format code ======================= (This note added 6.22.01 - better late than never). As part of the conversion step we have implemented a way of overriding the value of the AreaName variable on summary level 155 (place within county) summaries. On the Bureau file the value of AreaName on these records is the name of the county, but we prefer to have the name of the place. If you disagree with us, do a search right now for the string "To leave as-is" and follow the instructions to delete some lines and skip reading the rest of this section. If you want to change the AreaName on 155 summaries you need to use a SAS format code to do so. The code to USE such a format code is already written below. But the code to CREATE the format and make it accessible to your program is not. We recommend you go to the Missouri Census Data Center site (or the SDC Clearinghouse site if you a member of the State Data Center program) and get a fresh copy of the SAS source code that will let you create this format. The URL for accessing this code is: http://mcdc.missouri.edu/sasfmats/Sfplace.sas . (There was a file named fplace.sas in the original SDC distribution but that version had two problems that this one does not: 1. It was at least 2 years old and thus may have been missing entries for any places that came into being or changed codes or names since 1998 or so. 2. It contained the SAS statement: proc format ddname=library ; This can be a problem for those who have no idea what the "ddname=library" means and/or do not want to be bothered with setting up a special permanent catalog for storing this format. Download the format source code and put it in the same directory as this (cnvtsf1.sas) file. Then, add this code just prior to the data step that does the conversion: proc format ; %include 'Sfplace.sas'; *<---or whatever you named the file when you downloaded it.--; run; This defines the format code and you can now access it in the conversion step. It does not get saved in a permanent formats catalog so you will need to run this step in any job that needs to use the $fplace format code. If you would like to save a permanent copy of the format that can be accessed in future jobs without having to access the SAS source code you can code something along the following lines: libname library ''; proc format library=library; %include 'Sfplace.sas'; run; *--to make sure SAS knows to look in this permanent formats catalog so it can find $fplace you need to be sure that whatever library is referenced in the "library=" option of your proc format statement, is known to be one that SAS will search when trying to locate the format. This is handled by the fmtsearch option in SAS. E.g. you need to code something such as : options fmtsearch=(work library ); This would tell SAS to look for $fplace (or any other format code that it does not recognize as one of its own) first in the work.formats catalog, and then in the library.formats catalog. You may want to make this option a permanent part of your SAS environment by placing it in your autoexec.sas file. You can also include the "libname library .." statement there as well so that it will always be defined as part of your session initialization. --*; Parameters, etc. ================ To invoke this program to work for a specific set of files (presumably one state's worth) requires assigning some global macro variables and tweaking some other code. ****************************************IMPORTANT NOTE****************************************************** We have flagged parts of the code that may need to be altered with comments beginning with the characters "*<===". Be sure to search for all occurrences of this string to see what code you might need to change. You need to specify the state being converted by changing the line with %let statements defining the global parms stab and state. To run the program for Illinois, for example, make sure the line reads: %let stab=il; %let state=17; For consistency we strongly recommend using the lowercase for the value of stab. The maxobs parm can be assigned a value that will cause the program to run in test mode, stopping after processing the first &maxobs records off the input files. Use this for testing or when you want to do a temporary convert and know where the last record of interest is on the input files. For example, specify %let maxobs=1; to convert only the first (state summary) records. Assign a value to the inpath parameter to specify the path (directory) where the input files and output SAS data sets are stored. If you do not wish to store the SAS data sets in the same directory as the input files then you need to edit the "libname sf12000 ..." statement. A select macro is provided as a model and is referenced (invoked) within the conversion step. The code in this macro is executed after reading the geographic headers data, but **before** any data files are read. So it can access any of the fields/variables in the header record only. It needs to assign a value of 0 or 1 to the variable _keep. The program will interpret a value of _keep= to mean you want to skip processing this geographic area. It will handle the logic of skipping over the records in all 39 (at most, less for sub-tract geography) input files. Use this to code a "selective convert" of specific geographic entities. For example if you coded: if sumlev='160' and Pop100 ge 10000 then _keep=1; else _keep=0; You would be converting only place-level summaries for places with at least 10000 total population. ----------------------------------------------------------------------------------------------------------- */