OPTIONS LINESIZE=88 PAGESIZE=53 NOCENTER NODATE NONUMBER NOFMTERR; *******************************************************************; * PROJECT NAME: Learning to Use SAS ; * PROGRAM NAME LOCATION DATE PROGRAMMER ; TITLE1 "Source:LEC15P9.SAS Disk 1998#1 10/28/98 EJS " ; * Description: ; * Address List from SAS Language and Procedures, Ver 6, pp382 ; * Creating a city, state and Zip code variables ; * with minimal length ; *******************************************************************; FILENAME contacts 'c:\temp\lec15p5.txt'; DATA new1 (DROP=city state ctst lzip citys zip); INFILE contacts; INPUT id 2. name & $20. addr & $18. citys & $16. zip ; LABEL addr="Street/Address:/ADDR" citys="City/and/State:/CITYS" zip="Zip/Code:/ZIP" ctstz="City/State/ZIP:/CTSTZ"; city=SCAN(citys,1); state=SCAN(citys,2); lzip=LEFT(zip); ctst=TRIM(city)||', '||TRIM(state); ctstz=TRIM(city)||', '||TRIM(state)||' '||lzip; lctstz=LENGTH(ctstz); PROC MEANS DATA=new1 MAXDEC=0; VAR lctstz; TITLE2 "Table 5a. Length of city, state, zip code variable"; *****************************************; *** Set the length of the city,state,zip ; *** variable to be a minimum length ; *****************************************; DATA new2 (DROP=city state ctst lzip citys zip); INFILE contacts; LENGTH ctstz $ 23.; INPUT id 2. name & $20. addr & $18. citys & $16. zip ; LABEL addr="Street/Address:/ADDR" ctstz="City/State/ZIP:/CTSTZ"; city=SCAN(citys,1); state=SCAN(citys,2); lzip=LEFT(zip); ctst=TRIM(city)||', '||TRIM(state); ctstz=TRIM(city)||', '||TRIM(state)||' '||lzip; PROC CONTENTS DATA=new2; TITLE2 "Table 5b. Contents of Address List with Trimmed long Field Widths"; PROC PRINT DATA=new2 SPLIT="/"; ID id; VAR name addr ctstz; TITLE2 "Table 5c. Listing of Names and Address with City,State, Zip string"; RUN;