/* SAS codes in Chapter 2 */ ***2.2***; DATA distance; Miles = 26.22; Kilometers = 1.61 * Miles; RUN; DATA 'c:\MySASLib\distance'; Miles = 26.22; Kilometers = 1.61 * Miles; RUN; LIBNAME marathon 'c:\MySASLib'; DATA marathon.distance; Miles = 26.22; Kilometers = 1.61 * Miles; RUN; ***2.3***; * Use PROC CONTENTS to describe the CARS data set in the SASHELP library; PROC CONTENTS DATA = SASHELP.CARS; RUN; ***2.4***; LIBNAME sasfiles 'c:\MySASLib'; * Read an Excel spreadsheet using PROC IMPORT; PROC IMPORT DATAFILE = 'c:\MyExcel\Trees.xlsx' OUT = sasfiles.magnolia DBMS = XLSX REPLACE; RUN; ***2.5***; * Read an Excel spreadsheet using XLSX LIBNAME; LIBNAME exfiles XLSX 'c:\MyExcel\Trees.xlsx'; PROC PRINT DATA = exfiles.sheet1; TITLE 'PROC PRINT of Excel File'; RUN; * Read Excel into a permanent SAS data set; LIBNAME exfiles XLSX 'c:\MyExcel\Trees.xlsx'; LIBNAME sasfiles 'c:\MySASLib'; DATA sasfiles.magnolia; SET exfiles.sheet1; RUN; ***2.6***; PROC IMPORT DATAFILE ='c:\MyRawData\Bands2.csv' OUT = music REPLACE; RUN; ***2.7***; * Read internal data into SAS data set uspresidents; DATA uspresidents; INPUT President $ Party $ Number; DATALINES; Adams F 2 Lincoln R 16 Grant R 18 Kennedy D 35 ; RUN; * Read data from external file into SAS data set; DATA uspresidents; INFILE 'c:\MyRawData\President.dat'; INPUT President $ Party $ Number; RUN; ***2.8***; * Create a SAS data set named toads; * Read the data file ToadJump.dat using list input; DATA toads; LENGTH ToadName $ 9; INFILE 'c:\MyRawData\ToadJump.dat'; INPUT ToadName Weight Jump1 Jump2 Jump3; RUN; ***2.9***; * Create a SAS data set named sales; * Read the data file OnionRing.dat using column input; DATA sales; INFILE 'c:\MyRawData\OnionRing.dat'; INPUT VisitingTeam $ 1-20 CSales 21-24 BSales 25-28 OurHits 29-31 TheirHits 32-34 OurRuns 35-37 TheirRuns 38-40; RUN; ***2.10***; LIBNAME pump 'c:\MySASLib'; * Create a permanent SAS data set named contest; * Read the file Pumpkin.dat using formatted input; DATA pump.contest; INFILE 'c:\MyRawData\Pumpkin.dat'; INPUT Name $16. Age 3. +1 Type $1. +1 Date MMDDYY10. (Score1 Score2 Score3) (4.1); RUN; ***2.12***; * Create a SAS data set named nationalparks; * Read a data file NatPark.dat mixing input styles; DATA nationalparks; INFILE 'c:\MyRawData\NatPark.dat'; INPUT ParkName $ 1-22 State $ Year @40 Acreage COMMA9.; RUN; ***2.13***; DATA canoeresults; INFILE 'c:\MyRawData\Canoes.dat'; INPUT CanoeName & $13. @'School' School $ @'Time' RaceTime :STIMER8.; RUN; ***2.14***; * Create a SAS data set named highlow; * Read the data file using line pointers; DATA highlow; INFILE 'c:\MyRawData\Temperature.dat'; INPUT City $ State $ / NormalHigh NormalLow #3 RecordHigh RecordLow; RUN; ***2.15***; * Input more than one observation from each record; DATA rainfall; INFILE 'c:\MyRawData\Precipitation.dat'; INPUT City $ State $ NormalRain MeanDaysRain @@; RUN; ***2.16***; * Use a trailing @, then delete surface streets; DATA freeways; INFILE 'c:\MyRawData\Traffic.dat'; INPUT Type $ @; IF Type = 'surface' THEN DELETE; INPUT Name $ 9-38 AMTraffic PMTraffic; RUN; ***2.17***; DATA icecream; INFILE 'c:\MyRawData\IceCreamSales.dat' FIRSTOBS = 3; INPUT Flavor $ 1-9 Location BoxesSold; RUN; DATA icecream; INFILE 'c:\MyRawData\IceCreamSales2.dat' FIRSTOBS = 3 OBS=5; INPUT Flavor $ 1-9 Location BoxesSold; RUN; DATA class102; INFILE 'c:\MyRawData\AllScores.dat' MISSOVER; INPUT Name $ Test1 Test2 Test3 Test4 Test5; RUN; DATA homeaddress; INFILE 'c:\MyRawData\Address.dat' TRUNCOVER; INPUT Name $ 1-15 Number 16-19 Street $ 22-37; RUN;