![]() | ![]() | ![]() | ![]() | ![]() |
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 3.1
* Modify homegarden data set with assignment statements; DATA homegarden; INFILE 'c:\MyRawData\Garden.dat'; INPUT Name $ 1-7 Tomato Zucchini Peas Grapes; Zone = 14; Type = 'home'; Zucchini = Zucchini * 10; Total = Tomato + Zucchini + Peas + Grapes; PerTom = (Tomato / Total) * 100; RUN; PROC PRINT DATA = homegarden; TITLE 'Home Gardening Survey'; RUN;
Section 3.2
DATA contest;
INFILE 'c:\MyRawData\Pumpkin.dat';
INPUT Name $16. Age 3. +1 Type $1. +1 Date MMDDYY10.
(Scr1 Scr2 Scr3 Scr4 Scr5) (4.1);
AvgScore = MEAN(Scr1, Scr2, Scr3, Scr4, Scr5);
DayEntered = DAY(Date);
Type = UPCASE(Type);
RUN;
PROC PRINT DATA = contest;
TITLE 'Pumpkin Carving Contest';
RUN;
Section 3.5
DATA sportscars;
INFILE 'c:\MyRawData\UsedCars.dat';
INPUT Model $ Year Make $ Seats Color $;
IF Year < 1975 THEN Status = 'classic';
IF Model = 'Corvette' OR Model = 'Camaro' THEN Make = 'Chevy';
IF Model = 'Miata' THEN DO;
Make = 'Mazda';
Seats = 2;
END;
RUN;
PROC PRINT DATA = sportscars;
TITLE "Eddy’s Excellent Emporium of Used Sports Cars";
RUN;
Section 3.6
* Group observations by cost;
DATA homeimprovements;
INFILE 'c:\MyRawData\Home.dat';
INPUT Owner $ 1-7 Description $ 9-33 Cost;
IF Cost = . THEN CostGroup = 'missing';
ELSE IF Cost < 2000 THEN CostGroup = 'low';
ELSE IF Cost < 10000 THEN CostGroup = 'medium';
ELSE CostGroup = 'high';
RUN;
PROC PRINT DATA = homeimprovements;
TITLE 'Home Improvement Cost Groups';
RUN;
Section 3.7
* Choose only comedies; DATA comedy; INFILE 'c:\MyRawData\Shakespeare.dat'; INPUT Title $ 1-26 Year Type $; IF Type = 'comedy'; RUN; PROC PRINT DATA = comedy; TITLE 'Shakespearean Comedies'; RUN;
Section 3.8
DATA librarycards;
INFILE 'c:\MyRawData\Library.dat' TRUNCOVER;
INPUT Name $11. + 1 BirthDate MMDDYY10. +1 IssueDate ANYDTDTE10.
DueDate DATE11.;
DaysOverDue = TODAY() - DueDate;
Age = INT(YRDIF(BirthDate, TODAY(), 'ACTUAL'));
IF IssueDate > '01JAN2008'D THEN NewCard = 'yes';
RUN;
PROC PRINT DATA = librarycards;
FORMAT Issuedate MMDDYY8. DueDate WEEKDATE17.;
TITLE 'SAS Dates without and with Formats';
RUN;
Section 3.10
* Using RETAIN and sum statements to find most runs and total runs; DATA gamestats; INFILE 'c:\MyRawData\Games.dat'; INPUT Month 1 Day 3-4 Team $ 6-25 Hits 27-28 Runs 30-31; RETAIN MaxRuns; MaxRuns = MAX(MaxRuns, Runs); RunsToDate + Runs; RUN; PROC PRINT DATA = gamestats; TITLE "Season's Record to Date"; RUN;
Section 3.11
* Change all 9s to missing values;
DATA songs;
INFILE 'c:\MyRawData\WBRK.dat';
INPUT City $ 1-15 Age domk wj hwow simbh kt aomm libm tr filp ttr;
ARRAY song (10) domk wj hwow simbh kt aomm libm tr filp ttr;
DO i = 1 TO 10;
IF song(i) = 9 THEN song(i) = .;
END;
RUN;
PROC PRINT DATA = songs;
TITLE 'WBRK Song Survey';
RUN;
Section 3.12
DATA songs; INFILE 'c:\MyRawData\WBRK.dat';
INPUT City $ 1-15 Age domk wj hwow simbh kt aomm libm tr filp ttr;
ARRAY new (10) Song1 - Song10;
ARRAY old (10) domk -- ttr;
DO i = 1 TO 10;
IF old(i) = 9 THEN new(i) = .;
ELSE new(i) = old(i);
END;
AvgScore = MEAN(OF Song1 - Song10);
PROC PRINT DATA = songs;
TITLE 'WBRK Song Survey';
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 3.1, OutputHome Gardening Survey Obs Name Tomato Zucchini Peas Grapes Zone Type Total PerTom 1 Gregor 10 20 40 0 14 home 70 14.2857 2 Molly 15 50 10 1000 14 home 1075 1.3953 3 Luther 50 100 15 50 14 home 215 23.2558 4 Susan 20 0 . 20 14 home . .Section 3.2, Output
Pumpkin Carving Contest Avg Day Obs Name Age Type Date Scr1 Scr2 Scr3 Scr4 Scr5 Score Entered 1 Alicia Grossman 13 C 17833 7.8 6.5 7.2 8.0 7.9 7.48 28 2 Matthew Lee 9 D 17835 6.5 5.9 6.8 6.0 8.1 6.66 30 3 Elizabeth Garcia 10 C 17834 8.9 7.9 8.5 9.0 8.8 8.62 29 4 Lori Newcombe 6 D 17835 6.7 5.6 4.9 5.2 6.1 5.70 30 5 Jose Martinez 7 D 17836 8.9 9.5 10.0 9.7 9.0 9.42 31 6 Brian Williams 11 C 17834 7.8 8.4 8.5 7.9 8.0 8.12 29Section 3.5, Output
Eddy’s Excellent Emporium of Used Sports Cars Obs Model Year Make Seats Color Status 1 Corvette 1955 Chevy 2 black classic 2 XJ6 1995 Jaguar 2 teal 3 Mustang 1966 Ford 4 red classic 4 Miata 2002 Mazda 2 silver 5 CRX 2001 Honda 2 black 6 Camaro 2000 Chevy 4 redSection 3.6, Output
Home Improvement Cost Groups Cost Obs Owner Description Cost Group 1 Bob kitchen cabinet face-lift 1253.00 low 2 Shirley bathroom addition 11350.70 high 3 Silvia paint exterior . missing 4 Al backyard gazebo 3098.63 medium 5 Norm paint interior 647.77 low 6 Kathy second floor addition 75362.93 highSection 3.7, Output
Shakespearean Comedies Obs Title Year Type 1 A Midsummer Night’s Dream 1595 comedy 2 Comedy of Errors 1590 comedy 3 Taming of the Shrew 1593 comedySection 3.8, Output
SAS Dates without and with Formats Birth Issue Days New Obs Name Date Date DueDate OverDue Age Card 1 A. Jones 0 09/15/06 Fri, Feb 29, 2008 283 48 2 M. Rincon -3888 02/29/08 Fri, May 23, 2008 199 59 yes 3 Z. Grandage 10304 10/31/07 Sat, May 31, 2008 191 20 4 K. Kaminaka 15854 01/24/08 Thu, Jun 12, 2008 179 5 yesSection 3.10, Output
Season's Record to Date Max Runs Obs Month Day Team Hits Runs Runs ToDate 1 6 19 Columbia Peaches 8 3 3 3 2 6 20 Columbia Peaches 10 5 5 8 3 6 23 Plains Peanuts 3 4 5 12 4 6 24 Plains Peanuts 7 2 5 14 5 6 25 Plains Peanuts 12 8 8 22 6 6 30 Gilroy Garlics 4 4 8 26 7 7 1 Gilroy Garlics 9 4 8 30 8 7 4 Sacramento Tomatoes 15 9 9 39 9 7 4 Sacramento Tomatoes 10 10 10 49 10 7 5 Sacramento Tomatoes 2 3 10 52Section 3.11, Output
WBRK Song Survey Obs City Age domk wj hwow simbh kt aomm libm tr filp ttr i 1 Albany 54 4 3 5 . . 2 1 4 4 . 11 2 Richmond 33 5 2 4 3 . 2 . 3 3 3 11 3 Oakland 27 1 3 2 . . . 3 4 2 3 11 4 Richmond 41 4 3 5 5 5 2 . 4 5 5 11 5 Berkeley 18 3 4 . 1 4 . 3 . 3 2 11Section 3.12, Output
WBRK Song Survey A v S g s S S S S S S S S S o S C d h i a l f o o o o o o o o o n c O i A o w m o i i t n n n n n n n n n g o b t g m w o b k m b t l t g g g g g g g g g 1 r s y e k j w h t m m r p r 1 2 3 4 5 6 7 8 9 0 i e 1 Albany 54 4 3 5 9 9 2 1 4 4 9 4 3 5 . . 2 1 4 4 . 11 3.28571 2 Richmond 33 5 2 4 3 9 2 9 3 3 3 5 2 4 3 . 2 . 3 3 3 11 3.12500 3 Oakland 27 1 3 2 9 9 9 3 4 2 3 1 3 2 . . . 3 4 2 3 11 2.57143 4 Richmond 41 4 3 5 5 5 2 9 4 5 5 4 3 5 5 5 2 . 4 5 5 11 4.22222 5 Berkeley 18 3 4 9 1 4 9 3 9 3 2 3 4 . 1 4 . 3 . 3 2 11 2.85714
| Type: | Sample |
| Date Modified: | 2009-01-29 17:16:16 |
| Date Created: | 2009-01-09 09:21:00 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | Base SAS | z/OS | ||
| OpenVMS VAX | ||||
| Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
| Microsoft Windows XP 64-bit Edition | ||||
| Microsoft® Windows® for x64 | ||||
| OS/2 | ||||
| Microsoft Windows 95/98 | ||||
| Microsoft Windows 2000 Advanced Server | ||||
| Microsoft Windows 2000 Datacenter Server | ||||
| Microsoft Windows 2000 Server | ||||
| Microsoft Windows 2000 Professional | ||||
| Microsoft Windows NT Workstation | ||||
| Microsoft Windows Server 2003 Datacenter Edition | ||||
| Microsoft Windows Server 2003 Enterprise Edition | ||||
| Microsoft Windows Server 2003 Standard Edition | ||||
| Microsoft Windows XP Professional | ||||
| Windows Millennium Edition (Me) | ||||
| Windows Vista | ||||
| 64-bit Enabled AIX | ||||
| 64-bit Enabled HP-UX | ||||
| 64-bit Enabled Solaris | ||||
| ABI+ for Intel Architecture | ||||
| AIX | ||||
| HP-UX | ||||
| HP-UX IPF | ||||
| IRIX | ||||
| Linux | ||||
| Linux for x64 | ||||
| Linux on Itanium | ||||
| OpenVMS Alpha | ||||
| OpenVMS on HP Integrity | ||||
| Solaris | ||||
| Solaris for x64 | ||||
| Tru64 UNIX | ||||





