* SAS Sample Program "stf3a80.sas" ; /** This program reads tract level records from 1980 CENSUS SUMMARY TAPE FILE 3A. In dealing with this summary level one must take into account: 1) The tracts are presented in a geographic hierarchy: State County County Subdivision (MCD) Place Tract Because Tracts are unique within counties, but can cross county subdivision and even place boundries, there may be two or more records for each tract within the file. In order to get tract level counts, one must sum by state/county/tract. 2) Tract numbers are made of two parts: a 4 digit number and a two digit suffix. Some Tract numbers do not have suffixes. In those cases that part of the field is BLANK. In order to preserve the two part nature of the Tract numbers, these parts should be read as character variables and the Tract numbers should be created by combining the two parts with a period in between the two. Also, Note that this file contains 6 records per observation. **/ filename in1 'U:\ArchiveData\cen1980\003\da8071.dc11rev' lrecl=2016; libname ssd 'U:\Users\Your_netid\'; options ls=79; data ssd.data1; infile in1 lrecl=2016; INPUT sumlev 10-11@; if sumlev=14 then do; input state $34-35 cnty $40-42 tract4 $50-53 suffix $54-55 #3 @103 (t48001-t48005)(9.) #6; end; else delete; tract=tract4||'.'||suffix; /* CREATE A UNIQUE TRACT WITHIN COUNTY AND STATE */ /* UNIQUE TRACT:STATECODE+COUNTYCODE+TRACT */ tract_un = state||cnty||tract ; run; proc contents data=ssd.data1; title "CONTENTS OF THE SAS DATA SET" ; run; PROC freq data=ssd.data1 ; tables tract_un; title "FREQ OF UNIQUE_TRACTS:STATE+COUNTY+TRACT" ; run; /* MEANS OF THE VARIABLES BY TRACTS WITHIN COUNTY AND STATE */ proc sort data=ssd.data1 out=data_sor; by tract_un ; run; proc means data=data_sor ; by tract_un ; title "MEANS OF VAR BY STATE/COUNTY/TRACT" ; var t48001-t48005; run;