![]() | ![]() | ![]() | ![]() | ![]() |
Before you run the examples, open the zip file under the Downloads tab. Using the list below, create the folders and copy the data files so that the data are available during your SAS session.
Create the folder c:\MyRawData and copy these files to it:
Address.dat IceCreamSales.dat Shakespeare.dat Admit.dat IceCreamSales2.dat Shoe.dat AllScores.dat Lengths.dat Shoesales.dat Artists.dat Library.dat South.dat Baseball.dat LibraryBooks.dat Speed.dat Basketball.dat Mag.dat Survey.dat Boats2.dat Mens5000.dat Temperature.dat Boats.dat Mountains.dat Temps.dat Books.dat Movies.dat ToadJump.dat Bus.dat NatPark.Dat Tomatoes.dat Candy.dat NewAdmit.dat Traffic.dat Cars.dat North.dat Train.dat Choc.dat Olympic1500.dat Transpos.dat Chocolate.dat OnionRing.dat TropicalSales.dat Chocsales.dat Onions.dat UsedCars.dat Coffee.dat OrdersQ3.dat Walk.dat Criterium.dat Parks.dat WBRK.dat CustAddress.dat Picbooks.dat Zoo.dat Disc.dat Precipitation.dat Exercise.dat President.dat Bands.csv Flowers.dat Pumpkin.dat Bands2.csv Games.dat Records.dat Women.csv Garden.dat Scores.dat Home.dat SeaLife.datCreate the folder c:\MyFiles and copy this file to it: Baseball.xls
Create the folder c:\MyWebLogs and copy this file to it: dogweblogs.txt
Create the folder c:\MyExcelFiles and copy these files to it: Baseball.xls, OnionRing.xls
Create the folder c:\MyData to store files when you run examples
Create the folder c:\MyHTML to store files when you run examples
Create the folder c:\MyHTMLFiles to store files when you run examples
Create the folder c:\MyPDFFiles to store files when you run examples
Create the folder c:\MyRTFFiles to store files when you run examples
Create the folder c:\MySASLib and copy this file to it: TropicalSales.dat
Section 2.4
First program
* 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;Second program
* Read data from external file into SAS data set; DATA uspresidents; INFILE 'c:\MyRawData\President.dat'; INPUT President $ Party $ Number; RUN;
Section 2.5
* Create a SAS data set named toads; * Read the data file ToadJump.dat using list input; DATA toads; INFILE 'c:\MyRawData\ToadJump.dat'; INPUT ToadName $ Weight Jump1 Jump2 Jump3; RUN; * Print the data to make sure the file was read correctly; PROC PRINT DATA = toads; TITLE 'SAS Data Set Toads'; RUN;
Section 2.6
* 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 ConcessionSales 21-24 BleacherSales 25-28
OurHits 29-31 TheirHits 32-34 OurRuns 35-37 TheirRuns 38-40;
RUN;
* Print the data to make sure the file was read correctly;
PROC PRINT DATA = sales;
TITLE 'SAS Data Set Sales';
RUN;
Section 2.7
* Create a SAS data set named contest;
* Read the file Pumpkin.dat using formatted input;
DATA contest;
INFILE 'c:\MyRawData\Pumpkin.dat';
INPUT Name $16. Age 3. +1 Type $1. +1 Date MMDDYY10.
(Score1 Score2 Score3 Score4 Score5) (4.1);
RUN;
* Print the data set to make sure the file was read correctly;
PROC PRINT DATA = contest;
TITLE 'Pumpkin Carving Contest';
RUN;
Section 2.9
First Program
* 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; PROC PRINT DATA = nationalparks; TITLE 'Selected National Parks'; RUN;Second Program
* 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 Acreage COMMA9.; RUN; PROC PRINT DATA = nationalparks; TITLE 'Selected National Parks'; RUN;
Section 2.10
DATA weblogs; INFILE 'c:\MyWebLogs\dogweblogs.txt'; INPUT @'[' AccessDate DATE11. @'GET' File :$20.; RUN; PROC PRINT DATA = weblogs; TITLE 'Dog Care Web Logs'; RUN;
Section 2.11
* 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;
PROC PRINT DATA = highlow;
TITLE 'High and Low Temperatures for July';
RUN;
Section 2.12
* Input more than one observation from each record; DATA rainfall; INFILE 'c:\MyRawData\Precipitation.dat'; INPUT City $ State $ NormalRain MeanDaysRain @@; RUN; PROC PRINT DATA = rainfall; TITLE 'Normal Total Precipitation and'; TITLE2 'Mean Days with Precipitation for July'; RUN;
Section 2.13
* 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; PROC PRINT DATA = freeways; TITLE 'Traffic for Freeways'; RUN;
Section 2.14
First Program
DATA icecream; INFILE 'c:\MyRawData\IceCreamSales.dat' FIRSTOBS = 3; INPUT Flavor $ 1-9 Location BoxesSold; RUN;
Second ProgramDATA icecream; INFILE 'c:\MyRawData\IceCreamSales2.dat' FIRSTOBS = 3 OBS=5; INPUT Flavor $ 1-9 Location BoxesSold; RUN;Third ProgramDATA class102; INFILE 'c:\MyRawData\AllScores.dat' MISSOVER; INPUT Name $ Test1 Test2 Test3 Test4 Test5; RUN;Fourth ProgramDATA homeaddress; INFILE 'c:\MyRawData\Address.dat' TRUNCOVER; INPUT Name $ 1-15 Number 16-19 Street $ 22-37; RUN;Section 2.15
First Program
DATA reading; INFILE 'c:\MyRawData\Books.dat' DLM = ','; INPUT Name $ Week1 Week2 Week3 Week4 Week5; RUN;Third Program (second program intentionally omitted)DATA music; INFILE 'c:\MyRawData\Bands.csv' DLM = ',' DSD MISSOVER; INPUT BandName :$30. GigDate :MMDDYY10. EightPM NinePM TenPM ElevenPM; RUN; PROC PRINT DATA = music; TITLE 'Customers at Each Gig'; RUN;Section 2.16
PROC IMPORT DATAFILE ='c:\MyRawData\Bands2.csv' OUT = music REPLACE; RUN; PROC PRINT DATA = music; TITLE 'Customers at Each Gig'; RUN;Section 2.17
(data must be read from a spreadsheet) PROC IMPORT DATAFILE = 'c:\MyExcelFiles\OnionRing.xls' DBMS=XLS OUT = sales; RUN; PROC PRINT DATA = sales; TITLE 'SAS Data Set Read From Excel File'; RUN;Section 2.18
First Program (data must be read from a spreadsheet)
* Read an Excel spreadsheet using DDE; FILENAME baseball DDE 'CLIPBOARD'; DATA sales; INFILE baseball NOTAB DLM='09'x DSD MISSOVER; LENGTH VisitingTeam $ 20; INPUT VisitingTeam CSales BSales OurHits TheirHits OurRuns TheirRuns; RUN;Second Program (data must be read from a spreadsheet, must replace DDE triplet with DDE triplet for your own files* Read an Excel spreadsheet using DDE; OPTIONS NOXSYNC NOXWAIT; X '"C:\MyFiles\BaseBall.xls"'; FILENAME baseball DDE 'Excel|C:\MyFiles\[BaseBall.xls]sheet1!R2C1:R5C7'; DATA sales; INFILE baseball NOTAB DLM='09'x DSD MISSOVER; LENGTH VisitingTeam $ 20; INPUT VisitingTeam CSales BSales OurHits TheirHits OurRuns TheirRuns; RUN;Section 2.19
First Program
DATA distance; Miles = 26.22; Kilometers = 1.61 * Miles; RUN; PROC PRINT DATA = distance; RUN;Second ProgramDATA Bikes.distance; Miles = 26.22; Kilometers = 1.61 * Miles; RUN; PROC PRINT DATA = Bikes.distance; RUN;Section 2.20
First Program
LIBNAME plants 'c:\MySASLib'; DATA plants.magnolia; INFILE 'c:\MyRawData\Mag.dat'; INPUT ScientificName $ 1-14 CommonName $ 16-32 MaximumHeight AgeBloom Type $ Color $; RUN;Second ProgramLIBNAME example 'c:\MySASLib'; PROC PRINT DATA = example.magnolia; TITLE 'Magnolias'; RUN;Section 2.21
First Program
DATA 'c:\MySASLib\magnolia'; INFILE 'c:\MyRawData\Mag.dat'; INPUT ScientificName $ 1-14 CommonName $ 16-32 MaximumHeight AgeBloom Type $ Color $; RUN;Second ProgramPROC PRINT DATA = 'c:\MySASLib\magnolia'; TITLE 'Magnolias'; RUN;Section 2.22
DATA funnies (LABEL = 'Comics Character Data'); INPUT Id Name $ Height Weight DoB MMDDYY8. @@; LABEL Id = 'Identification no.' Height = 'Height in inches' Weight = 'Weight in pounds' DoB = 'Date of birth'; INFORMAT DoB MMDDYY8.; FORMAT DoB WORDDATE18.; DATALINES; 53 Susie 42 41 07-11-81 54 Charlie 46 55 10-26-54 55 Calvin 40 35 01-10-81 56 Lucy 46 52 01-13-55 ; * Use PROC CONTENTS to describe data set funnies; PROC CONTENTS DATA = funnies; RUN;The sample is authored by Lora D. Delwiche and Susan J. Slaughter.
Their book The Little SAS Book: A Primer, Fourth Edition is available for sale in our online bookstore.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
(Section 2.5, Output)SAS Data Set Toads Toad Obs Name Weight Jump1 Jump2 Jump3 1 Lucky 2.3 1.9 . 3.0 2 Spot 4.6 2.5 3.1 0.5 3 Tubs 7.1 . . 3.8 4 Hop 4.5 3.2 1.9 2.6 5 Noisy 3.8 1.3 1.8 1.5 6 Winner 5.7 . . .(Section 2.6, Output)
SAS Data Set Sales Concession Bleacher Our Their Our Their Obs VisitingTeam Sales Sales Hits Hits Runs Runs 1 Columbia Peaches 35 67 1 10 2 1 2 Plains Peanuts 210 . 2 5 0 2 3 Gilroy Garlics 15 1035 12 11 7 6 4 Sacramento Tomatoes 124 85 15 4 9 1(Section 2.7, Output)
Pumpkin Carving Contest Obs Name Age Type Date Score1 Score2 Score3 Score4 Score5 1 Alicia Grossman 13 c 17833 7.8 6.5 7.2 8.0 7.9 2 Matthew Lee 9 D 17835 6.5 5.9 6.8 6.0 8.1 3 Elizabeth Garcia 10 C 17834 8.9 7.9 8.5 9.0 8.8 4 Lori Newcombe 6 D 17835 6.7 5.6 4.9 5.2 6.1 5 Jose Martinez 7 d 17836 8.9 9.5 10.0 9.7 9.0 6 Brian Williams 11 C 17834 7.8 8.4 8.5 7.9 8.0(Section 2.9, Program 1 Output)
Selected National Parks Obs ParkName State Year Acreage 1 Yellowstone ID/MT/WY 1872 4065493 2 Everglades FL 1934 1398800 3 Yosemite CA 1864 760917 4 Great Smoky Mountains NC/TN 1926 520269 5 Wolf Trap Farm VA 1966 130(Section 2.9, Program 2 Output)
Selected National Parks Obs ParkName State Year Acreage 1 Yellowstone ID/MT/WY 1872 4065 2 Everglades FL 1934 . 3 Yosemite CA 1864 . 4 Great Smoky Mountains NC/TN 1926 5 5 Wolf Trap Farm VA 1966 .(Section 2.10, Output)
Dog Care Web Logs Access Obs Date File 1 17691 /rover.jpg 2 17691 /grooming.html 3 17691 /Icons/brush.gif 4 17691 /H_poodle.gif 5 17691 /bath.gif 6 17692 /lobo.gif 7 17692 /statemnt.htm 8 17692 /Icons/leash.gif(Section 2.11, Output)
High and Low Temperatures for July Normal Normal Record Record Obs City State High Low High Low 1 Nome AK 55 44 88 29 2 Miami FL 90 75 97 65 3 Raleigh NC 88 68 105 50(Section 2.12, Output)
Normal Total Precipitation and Mean Days with Precipitation for July Normal Mean Obs City State Rain DaysRain 1 Nome AK 2.50 15 2 Miami FL 6.75 18 3 Raleigh NC . 12(Section 2.13, Output)
Traffic for Freeways Obs Type Name AMTraffic PMTraffic 1 freeway 408 3684 3459 2 freeway 608 4583 3860 3 freeway 808 2386 2518(Section 2.15, Output from Third Program)
Customers at Each Gig Gig Eight Nine Ten Eleven Obs BandName Date PM PM PM PM 1 Lupine Lights 17503 45 63 70 . 2 Awesome Octaves 17515 17 28 44 12 3 Stop, Drop, and Rock-N-Roll 17536 34 62 77 91 4 The Silveyville Jazz Quartet 17549 38 30 42 43 5 Catalina Converts 17562 56 . 65 34 6 . . . . . 7 . . . . . 8 . . . . .(Section 2.16, Output)
Customers at Each Gig Obs Band_Name Gig_Date Eight_PM 1 Lupine Lights 12/03/2007 45 2 Awesome Octaves 12/15/2007 17 3 Stop, Drop, and Rock-N-Roll 01/05/2008 34 4 The Silveyville Jazz Quartet 01/18/2008 38 5 Catalina Converts 01/31/2008 56 Obs Nine_PM Ten_PM Eleven_PM 1 63 70 . 2 28 44 12 3 62 77 91 4 30 42 43 5 . 65 34(Section 2.17, Output)
SAS Data Set Read From Excel File Concession Bleacher Our Their Our Their Obs VisitingTeam Sales Sales Hits Hits Runs Runs 1 Columbia Peaches 35 67 1 10 2 1 2 Plains Peanuts 210 . 2 5 0 2 3 Gilroy Garlics 15 1035 12 11 7 6 4 Sacramento Tomatoes 124 85 15 4 9 1 SAS Data Set Read From Excel File Obs Miles Kilometers 1 26.22 42.2142(Section 2.20, Output from Second Program)
Magnolias Maximum Age Obs ScientificName CommonName Height Bloom Type Color 1 M. grandiflora Southern Magnolia 80 15 E white 2 M. campbellii 80 20 D rose 3 M. liliiflora Lily Magnolia 12 4 D purple 4 M. soulangiana Saucer Magnolia 25 3 D pink 5 M. stellata Star Magnolia 10 3 D white(Section 2.21, Output from Second Program)
Magnolias Maximum Age Obs ScientificName CommonName Height Bloom Type Color 1 M. grandiflora Southern Magnolia 80 15 E white 2 M. campbellii 80 20 D rose 3 M. liliiflora Lily Magnolia 12 4 D purple 4 M. soulangiana Saucer Magnolia 25 3 D pink 5 M. stellata Star Magnolia 10 3 D white(Section 2.22, Output)
Magnolias The CONTENTS Procedure Data Set Name WORK.FUNNIES Observations 4 Member Type DATA Variables 5 Engine V9 Indexes 0 Created Wed, Sep 24, 2008 10:30:34 AM Observation Length 40 Last Modified Wed, Sep 24, 2008 10:30:34 AM Deleted Observations 0 Protection Compressed NO Data Set Type Sorted NO Label Comics Character Data Data Representation WINDOWS_32 Encoding wlatin1 Western (Windows) Engine/Host Dependent Information Data Set Page Size 4096 Number of Data Set Pages 1 First Data Page 1 Max Obs per Page 101 Obs in First Data Page 4 Number of Data Set Repairs 0 Filename C:\DOCUME~1\sassqj\LOCALS~1\Temp\SAS Temporary Files\_TD3568\funnies.sas7bdat Release Created 9.0201M0 Host Created XP_PRO Alphabetic List of Variables and Attributes # Variable Type Len Format Informat Label 5 DoB Num 8 WORDDATE18. MMDDYY8. Date of birth 3 Height Num 8 Height in inches 1 Id Num 8 Identification no. 2 Name Char 8 4 Weight Num 8 Weight in pounds
| Type: | Sample |
| Date Modified: | 2009-01-29 17:15:41 |
| Date Created: | 2008-10-01 10:37:30 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | Base SAS | z/OS | 9.2 TS2M0 | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS2M0 | |||
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS2M0 | |||
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS2M0 | |||
| Microsoft Windows XP 64-bit Edition | 9.2 TS2M0 | |||
| Microsoft® Windows® for x64 | 9.2 TS2M0 | |||
| Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS2M0 | |||
| Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS2M0 | |||
| Microsoft Windows Server 2003 Standard Edition | 9.2 TS2M0 | |||
| Microsoft Windows XP Professional | 9.2 TS2M0 | |||
| Windows Vista | 9.2 TS2M0 | |||
| 64-bit Enabled AIX | 9.2 TS2M0 | |||
| 64-bit Enabled HP-UX | 9.2 TS2M0 | |||
| 64-bit Enabled Solaris | 9.2 TS2M0 | |||
| HP-UX IPF | 9.2 TS2M0 | |||
| Linux | 9.2 TS2M0 | |||
| Linux for x64 | 9.2 TS2M0 | |||
| OpenVMS on HP Integrity | 9.2 TS2M0 | |||
| Solaris for x64 | 9.2 TS2M0 | |||





