x cd /pub/data/sf12010/Tools; %let pgm=gen_sdcprofiles_aspdffiles; filename pgm "&pgm..sas"; *---This is an adaptation of the code stored in acsprofiles/SF1_main_2010_pdf.sas . We are editing it so that we can generate a library of pdf files for Missouri geography. J. Blodgett, OSEDA, Missouri Census Data Center, August, 2011. ---*; /*----- "Main.SAS", SDC 2010 SF1 Profiles Main Routine Coded by John Blodgett, OSEDA/U. of Missouri, & Roy Williams, MISER/UMass 7/10/01 [original code, being adapted for the new decade]. Users need to edit at most 12 places in this routine. They're marked below with * to *. Usually only 5 or 6 of these need changing: 1. Location of (path to) data set (e.g. R:\Census 2010\SF1\ProfTest) 2. Full path & name of ODS (ps/pdf) output file--or comment out and let output go only to the standard (non-ODS) destination selected in 7. below. 3. What state's files to read (stab=ca) 4. Which of the 4 profile modules (profiles=...) & optionally, which pages within a profile (necessary when you don't want all pages of a given profile; for example, pages1=127, pages3=ABC, etc.) 5. Name of data set to read (such as CAINVENTORY, or a MERGE of the 3 data sets for California, or a custom data set) 6. Which geographic area(s) (WHERE...--usually not needed for a custom set) 7. Selection of standard display destination: the standard Display Manager output window (FILE PRINT) or a plain text file (FILE "name.prn") or neither if the ODS (ps/pdf) destination is selected 8. Setting for Table of Contents page: TOC=1 if desired only once, TOC=0 to suppress completely, TOC=2 for generation with every profile 9. Setting or commenting out of "custom=1" to turn calculation of custom medians and household sizes on or off (usually commented out) 10. Stopping criterion (IF [some condition is true] THEN STOP --usually based on estimated total AreaCount) 11. Setting for cumulative paging (1 for cumulative, 0 to start each area with p.1) 12. Localize the credit line in the page footer Users may need to fine-tune SAS version/operating system differences. ------*/ ***ODS HTML CLOSE ; %GLOBAL profiles pages1 pages2 pages3 pages4 geocomps linesize CumulPaging ; %LET linesize=149 ; * Macro var still used by macro "PUTTitle" in GenProf's ; %LET CumulPaging=0 ; %* turns off cumulative paging for this run (your preference) ; OPTIONS LINESIZE=149 PAGESIZE=64 PAGENO=1 NODATE NONUMBER ORIENTATION=LANDSCAPE ; OPTIONS FORMCHAR="|----|+|---+=|-/\<>*"; TITLE ; * Blanks out "The SAS System" title in ODS output ; * Location of (path to) data set ; LIBNAME sf12000 '/pub/data/sf12010'; ***LIBNAME library 'R:\Census 2010\SF1\ProfTest'; * for stored format $County. ; FILENAME sascode '/pub/data/sf12010/sdcprofiles'; * directory where we get the GenProfX modules ; * defining appropriate Style for ODS PS/PDF output--needs to be run only once, since it will automatically get saved in a SASUSER location. Version 8.2 doesn't allow for hard page breaks in ODS "batch" print output, but 1/2" margins cause appropriate breaks every 64 lines, at least on my Windows2000 machine here at MISER with Adobe Acrobat 5.0 ; proc template ; define style SF1style; parent=styles.printer; style body from body / /* results in 64 lines per page */ leftmargin= .5in rightmargin= .5in topmargin= .5in bottommargin=.5in; replace fonts / 'BatchFixedFont' = ("Courier",8pt) /* The only font actually used */ 'TitleFont2' = ("Times Roman",8pt,Bold Italic) 'TitleFont' = ("Times Roman",8pt,Bold Italic) 'StrongFont' = ("Times Roman",8pt,Bold) 'EmphasisFont' = ("Times Roman",8pt,Italic) 'FixedEmphasisFont' = ("Courier",8pt,Italic) 'FixedStrongFont' = ("Courier",8pt,Bold) 'FixedHeadingFont' = ("Courier",8pt,Bold) 'FixedFont' = ("Courier",8pt) 'headingEmphasisFont' = ("Times Roman",8pt,Bold Italic) 'headingFont' = ("Times Roman",8pt,Bold) 'docFont' = ("Times Roman",8pt); end; run; /* selecting PostScript instead of pdf gets around indentation/alignment bug in SAS Version 8.2, but it means user must run Adobe Distiller to "distill" resulting file from ps to pdf. Distiller automatically saves "name.pdf" in the same location as "name.ps". Turning on "pdfmark" option will allow adding pdf bookmarks later, or so I'm told. Haven't tried it yet. */ * Fill in name of desired output pdf file, but leave the ".ps", not ".pdf" ; *ODS ps file="R:\Census 2010\SF1\ProfTest\CALIF_2010_PROFILE.ps" pdfmark style=SF1style ; ODS pdf file="/pub/reports/sf12010_sdcprofiles/test.ps" pdfmark style=SF1style ; *<==Specify postal abbreviation of the state file to access; %LET stab=mo; /* Select only one of the following setups for editing, and leave all the others commented out; if slash-star & star-slash brackets are correct the "%LET geocomp=00" at the end should be active (i.e. shows up blue in the SAS Program Editor window, not commented out in green) */ /* extreme example -- would generate all 58 pages if all 4 "pages" variables are left undefined ; %LET profiles=1234 ; */ /* opposite extreme: only page 1 of Section ("profile") 2 ; %LET profiles=2 ; %LET pages2=1 ; */ %LET profiles=1234; %LET pages1=123456789 ; %LET pages2=12 ;%LET pages3=ABCDEFGHIJKLMNO; %LET pages4=1234ABCDEFGHI; %let profiles=1; %LET geocomps=00; *<===specify additional geocomp codes (2-digit, separated by blanks) in the unlikely event that you want profiles for geog components other than the default "00" (which means "NOT a geographic component")--; DATA _NULL_; *-------This is the step that generates the profiles!-------*; * Select only one - either the SET or MERGE statement ; * custom data set created by S1Sum.sas--no WHERE statement needed ; MERGE sf12000.&stab.inventory sf12000.&stab.pcos sf12000.&stab.phctr; BY logrecno; * Area selection here-- (Comment out the previous selection but leave it there as an example.) ; * WHERE sumlev ='080' & CouSubFP='01325' ; * All tracts (parts!) in Amherst ; * whole tract (all MA tract codes unique except a few 01xx.xx's & 04xx.xx's -- Remember the dec. pt. and 0's) ; *WHERE sumlev ='155' and placefp = '56938'; *WHERE sumlev ='050' & county IN ('06001','06013','06015') ; * 3 counties ; * WHERE sumlev ='050' ; * All county records in the file ; * WHERE CouSubFP IN ('03005','28950','61590','72215') ; * 4 MCD's ; * WHERE sumlev ='871'& ZCTA5='02127' ; * 5-digit ZIP code ; * WHERE AreaName =: 'Boston' ; * "=:" means "starts with" ; * WHERE AreaName IN: ('Hampshi','Chester') ; * a county & 2 towns! ; * WHERE sumlev='091' AND county='06001' and tract = '4271.00' and BG = '1'; *BG ; WHERE sumlev ='040' ; * state ; * WHERE StSenDist='10' ; * WHERE type='PUMA' ; * Boston City 5 PUMAs ; * where sumlev in ('040','050'); *<---state and county only---; IF INDEX("&geocomps",geocomp) NE 0 ; * First FILE statement sends to standard Display Manager window (which can be later saved as a plain text file without page breaks or sent to a real printer or "printed" to a pdf file.) The second FILE statement saves the output as a plain text file with page breaks. (comment out one or both file statements) ; FILE PRINT LINESIZE=149 PAGESIZE=64 N=PAGESIZE NOTITLES; * FILE "J:\Cens2000\sf1\BigProf\Boston.prn" PRINT LINESIZE=149 PAGESIZE=64 N=PAGESIZE NOTITLES ; * Set TOC=1 to generate Table of Contents page only once at the beginning of the run, set TOC=0 to suppress completely if not desired, set it > 1 to generate page at the beginning of each profile generated in the run ; TOC=1 ; * Custom areas (e.g. BRA & legis areas) need age medians & household sizes calculated--comment out for standard areas where already done in data set ; * Custom=1 ; PCT= ( sumlev not in ('091','101','150','154') ); *--These are the sub-Census Tract levels with no "CT" tables-; AreaCount+1; * (i.e. bump up the count of areas processed by one) ; * Stopping criterion in case your WHERE statement accidentally asked for hundreds of areas--you can also use other variables here or overestimate expected number or comment this out if you don't know how many to expect ; *IF AreaCount>1 THEN STOP ; IF AreaCount LE 199 OR MOD(AreaCount,50)=0 THEN DO ; FILE LOG; PUT sumlev= Pop100= GeoCode= AreaName= ; FILE PRINT; END ; RETAIN strtline 6 RunPage 0 ; * If cumulative page numbering is set to false (0), each area will start with page 1 ; IF (&CumulPaging=0) THEN RunPage=0 ; LENGTH Underline DoubleLine SingleLine $149 profiles $6; RETAIN profiles "&profiles" Underline DoubleLine SingleLine VBAR '|' PLUS '+' _first 1; IF _first=1 THEN DO; RunDate="&sysdate"; RETAIN RunDate; * LENGTH TITLE $134; * will be assigned a value for each page ; UnderLine= REPEAT('_',147) ; DoubleLine=REPEAT('=',147) ; SingleLine=REPEAT('-',147) ; profiles=SYMGET('PROFILES'); IF profiles=' ' OR UPCASE(profiles)='ALL' THEN profiles='13456'; _first=0; END; * General macro which calculates any median using linear interpolation. ; %INCLUDE SASCode('calcmedian.sas') ; * Macro to calculate all 30 median ages (total pop & 9 race groups by sex) using P12, P12A-P12I. Called below for custom-defined areas only. Also called by GenProf4 whenever any of the races J through O are requested) ; ARRAY P12LowBounds [23] _TEMPORARY_ (0, 5,10, 15,18, 20,21,22, 25,30,35,40, 45,50,55, 60,62, 65,67, 70,75,80,85) ; %Macro MedAge(Race) ; ARRAY P12&Race.male23 [23] P12&Race.i3 -P12&Race.i25 ; ARRAY P12&Race.feml23 [23] P12&Race.i27-P12&Race.i49 ; ARRAY P12&Race.Both23 [23] ; DO age = 1 TO 23 ; P12&Race.Both23[age] = P12&Race.male23[age] + P12&Race.feml23[age] ; END ; %CalcMedian (P13&Race.i1, 23, P12LowBounds, P12&Race.Both23, P12&Race.i1) ; %CalcMedian (P13&Race.i2, 23, P12LowBounds, P12&Race.male23, P12&Race.i2) ; %CalcMedian (P13&Race.i3, 23, P12LowBounds, P12&Race.feml23, P12&Race.i26) ; %MEnd ; * Macro to calculate 50 average sizes (by race by HH type or tenure.) If a denominator is zero, all components are zeros and sums of the Avg Sizes from components will already contain zero. ; * Denominators for Avg HU size by tenure by race assembled from various other tables without a consistent Race letter, so using 0 to 9 for total pop & nine races ; ARRAY OccHU [3,0:9] H6i1-H6i8 H15Hi1 H15Ii1 /* Hisp & WhiteNH not in H6 & H14 */ H14i2-H14i9 H15Hi2 H15Ii2 /* Owners */ H14i10-H14i17 H15Hi10 H15Ii10 ; /* Renters */ %Macro AvgSize(Race,RNo) ; IF (P15&Race.i1>0) THEN P17&Race.i1=P16&Race.i1/P15&Race.i1 ; * Households ; IF (P31&Race.i1>0) THEN P33&Race.i1=P32&Race.i1/P31&Race.i1 ; * Families ; IF (OccHU[1,&RNo]>0) THEN H12&Race.i1=H11&Race.i1/OccHU [1,&RNo] ; * all Occ HUnits ; IF (OccHU[2,&RNo]>0) THEN H12&Race.i2=H11&Race.i2/OccHU [2,&RNo] ; * OwnerOcc HU ; IF (OccHU[3,&RNo]>0) THEN H12&Race.i3=H11&Race.i3/OccHU [3,&RNo] ; * RenterOcc HU ; %MEnd ; /*IF Custom THEN DO ; * In first call to %MedAge, Race is null (for total pop) ; %MedAge () ; %MedAge (A) ; %MedAge (B) ; %MedAge (C) ; %MedAge (D) ; %MedAge (E) ; %MedAge (F) ; %MedAge (G) ; %MedAge (H) ; %MedAge (I) ; * In first call to %AvgSize, Race is null and zero (for total pop) ; %AvgSize ( ,0) ; %AvgSize (A,1) ; %AvgSize (B,2) ; %AvgSize (C,3) ; %AvgSize (D,4) ; %AvgSize (E,5) ; %AvgSize (F,6) ; %AvgSize (G,7) ; %AvgSize (H,8) ; %AvgSize (I,9) ; END ;*/ LENGTH _pages $16; IF (TOC>1 or (TOC=1 AND AreaCount=1)) THEN LINK PageTOC ; IF INDEX(PROFILES,'1')THEN DO; pno='1'; _pages="&pages1"; LINK GenProf1; IF _ERROR_ THEN LINK err; END; IF INDEX(PROFILES,'2')THEN DO; pno='2'; _pages="&pages2"; LINK GenProf2; IF _ERROR_ THEN LINK err; END; IF INDEX(PROFILES,'3')THEN DO; pno='3'; _pages="&pages3"; LINK GenProf3; IF _ERROR_ THEN LINK err; END; IF INDEX(PROFILES,'4')THEN DO; pno='4'; _pages="&pages4"; LINK GenProf4; IF _ERROR_ THEN LINK err; END; RETURN; *---end main routine. Now come the linked-to routines---; err: *---Handles errors encountered while generating profiles---; FILE LOG; _nerr+1; IF _nerr LE 20 THEN PUT '** Error detected (probably division by zero) ' 'while processing profile ' PNO ' for ' AREANAME; _ERROR_=0; ** turn off flag, avoid dump **; IF _nerr EQ 20 THEN DO; PUT // '** NO MORE OF THESE MESSAGES WILL BE PRINTED **'; END; FILE PRINT; RETURN; *<---main program loop ends with above return stmt. The following include statements reference the SASCode library where the links to generate the profiles reside--; OPTIONS SOURCE2 NOMPRINT ; *<====after debugging----; /*OPTIONS NOSOURCE2 NOMPRINT ;*/ *<====after debugging----; %INCLUDE SASCode(PageTOC) ; *--Roy Williams, Massachusetts--; %INCLUDE SASCode(GenProf1) ; *----; %INCLUDE SASCode(GenProf2) ; *----; %INCLUDE SASCode(GenProf3) ; *----; %INCLUDE SASCode(GenProf4) ; *----; HeadFoot: /* This routine is invoked after the body of each profile page is complete. Puts the headers, footers and vertical lines on either side. Rest of line #1 (centered TITLE) already PUT in by GenProfN */ PUT #1 'Census 2010, Summary File 1' ; if geocomp eq '00' then put #2 'Area Name: ' AreaName ; else put #2 'Area: ' AreaName 'Component:' geocomp $geocomp. ; *<===Could comment out above else statement if not generating geocomp summaries. Must have defined the $geocomp. format to use this line; LENGTH TypeString $ 60 ; TypeString='Area Type: '|| TRIM(PUT(SumLev,$SumLev.))||' (Summary Level: '||SumLev||')' ; *<=== Users may want to build TypeString using LSADC along with SumLev for some kinds of areas--it has more specific categories (Parishes, Boroughs, etc.) ; PUT #2 @(%eval(&linesize+1) - LENGTH(TypeString)) TypeString ; LENGTH GeoString $&linesize ; GeoString=' ' ; IF (StAb NE ' ') THEN GeoString='State: '||UPCASE(StAb) ; IF (cnty NE ' ') THEN DO ; GeoString=TRIM(GeoString)||' County: '||cnty ; * user will need to have the $county. format source code--; IF (SumLev NE '050' ) THEN geostring= TRIM(geostring)||' ('||TRIM(PUT(county,$county.))||')'; END ; IF (CouSubFP NE ' ') THEN GeoString=TRIM(GeoString)||' CouSub: '||CouSubFP ; IF (PlaceFP NE ' ') THEN GeoString=TRIM(GeoString)||' Place: '||PlaceFP ; IF (Tract NE ' ') THEN GeoString=TRIM(GeoString)||' Tract: '||Tract ; IF (BG NE ' ' and Block EQ ' ' ) THEN GeoString=TRIM(GeoString)||' BG: '||BG ; IF (Block NE ' ') THEN GeoString=TRIM(GeoString)||' Block: '||Block ; * still need to add UA., MSA, etc. to GeoString ; PUT #3 GeoString ; *---Draw the box around the tabular area incl left and right vertical lines--; PUT #5 @1 PLUS $1. DoubleLine $147. PLUS $1. ; DO _I_=strtline TO 61; PUT #_I_ @1 VBAR $1. @149 VBAR $1. @; END ; * Localize the credit line in the page footer; *----Footers including bottom of box--------; RunPage + 1 ; * Cumulative paging would run from 1 to (# of areas) x (# of profiles) ; %LET credline= %STR(Profile prepared by the Missouri Census Data Center, mcdc.missouri.edu); LENGTH credline $148 ; RETAIN credline "&credline"; PUT #62 @1 PLUS $1. DoubleLine $147. PLUS $1. / @1 "Source: Census 2010 Summary File 1 [machine-readable data file]/prepared" " by the U.S.Census Bureau, 2011 " @123 RunDate +(-1) @140 'Page ' RunPage 3.0-L / @1 credline @ ; * PUT _PAGE_ probably unnecessary if trailing-@ removed? ; PUT _PAGE_ ; RETURN; *************end HeadFoot routine**************; RUN; ODS pdf close ; %PUT state=&stab profiles=&profiles geocomps=&geocomps pages= &pages1/&pages2/&pages3/&pages4/; %include '/pub/sascode/notify.sas';