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 4.2
First Program DATA 'c:\MySASLib\style'; INFILE 'c:\MyRawData\Artists.dat'; INPUT Name $ 1-21 Genre $ 23-40 Origin $ 42;
Second Program PROC PRINT DATA = 'c:\MySASLib\style'; WHERE Genre = 'Impressionism'; TITLE 'Major Impressionist Painters'; FOOTNOTE 'F = France N = Netherlands U = US'; RUN; Turn off footnote FOOTNOTE;
Section 4.3
DATA marine; INFILE 'c:\MyRawData\Lengths.dat'; INPUT Name $ Family $ Length @@; RUN; * Sort the data; PROC SORT DATA = marine OUT = seasort NODUPKEY; BY Family DESCENDING Length; PROC PRINT DATA = seasort; TITLE 'Whales and Sharks'; RUN;
Section 4.4
DATA sales; INFILE 'c:\MyRawData\Candy.dat'; INPUT Name $ 1-11 Class @15 DateReturned MMDDYY10. CandyType $ Quantity; Profit = Quantity * 1.25; PROC SORT DATA = sales; BY Class; PROC PRINT DATA = sales; BY Class; SUM Profit; VAR Name DateReturned CandyType Profit; TITLE 'Candy Sales for Field Trip by Class'; RUN;
Section 4.5
DATA sales; INFILE 'c:\MyRawData\Candy.dat'; INPUT Name $ 1-11 Class @15 DateReturned MMDDYY10. CandyType $ Quantity; Profit = Quantity * 1.25; PROC PRINT DATA = sales; VAR Name DateReturned CandyType Profit; FORMAT DateReturned DATE9. Profit DOLLAR6.2; TITLE 'Candy Sale Data Using Formats'; RUN;
Section 4.7
DATA carsurvey; INFILE 'c:\MyRawData\Cars.dat'; INPUT Age Sex Income Color $; PROC FORMAT; VALUE gender 1 = 'Male' 2 = 'Female'; VALUE agegroup 13 -< 20 = 'Teen' 20 -< 65 = 'Adult' 65 - HIGH = 'Senior'; VALUE $col 'W' = 'Moon White' 'B' = 'Sky Blue' 'Y' = 'Sunburst Yellow' 'G' = 'Rain Cloud Gray'; * Print data using user-defined and standard (DOLLAR8.) formats; PROC PRINT DATA = carsurvey; FORMAT Sex gender. Age agegroup. Color $col. Income DOLLAR8.; TITLE 'Survey Results Printed with User-Defined Formats'; RUN;
Section 4.8
* Write a report with FILE and PUT statements; DATA _NULL_; INFILE 'c:\MyRawData\Candy.dat'; INPUT Name $ 1-11 Class @15 DateReturned MMDDYY10. CandyType $ Quantity; Profit = Quantity * 1.25; FILE 'c:\MyRawData\Student.txt' PRINT; TITLE; PUT @5 'Candy sales report for ' Name 'from classroom ' Class // @5 'Congratulations! You sold ' Quantity 'boxes of candy' / @5 'and earned ' Profit DOLLAR6.2 ' for our field trip.'; PUT _PAGE_; RUN;
Section 4.9
DATA sales; INFILE 'c:\MyRawData\Flowers.dat'; INPUT CustomerID $ @9 SaleDate MMDDYY10. Petunia SnapDragon Marigold; Month = MONTH(SaleDate); PROC SORT DATA = sales; BY Month; * Calculate means by Month for flower sales; PROC MEANS DATA = sales; BY Month; VAR Petunia SnapDragon Marigold; TITLE 'Summary of Flower Sales by Month'; RUN;
Section 4.10
DATA sales; INFILE 'c:\MyRawData\Flowers.dat'; INPUT CustomerID $ @9 SaleDate MMDDYY10. Petunia SnapDragon Marigold; PROC SORT DATA = sales; BY CustomerID; * Calculate means by CustomerID, output sum and mean to new data set; PROC MEANS NOPRINT DATA = sales; BY CustomerID; VAR Petunia SnapDragon Marigold; OUTPUT OUT = totals MEAN(Petunia SnapDragon Marigold) = MeanPetunia MeanSnapDragon MeanMarigold SUM(Petunia SnapDragon Marigold) = Petunia SnapDragon Marigold; PROC PRINT DATA = totals; TITLE 'Sum of Flower Data over Customer ID'; FORMAT MeanPetunia MeanSnapDragon MeanMarigold 3.; RUN;
Section 4.11
DATA orders; INFILE 'c:\MyRawData\Coffee.dat'; INPUT Coffee $ Window $ @@; * Print tables for Window and Window by Coffee; PROC FREQ DATA = orders; TABLES Window Window * Coffee; RUN;
Section 4.12
DATA boats; INFILE 'c:\MyRawData\Boats.dat'; INPUT Name $ 1-12 Port $ 14-20 Locomotion $ 22-26 Type $ 28-30 Price 32-36; RUN; * Tabulations with three dimensions; PROC TABULATE DATA = boats; CLASS Port Locomotion Type; TABLE Port, Locomotion, Type; TITLE 'Number of Boats by Port, Locomotion, and Type'; RUN;
Section 4.13
DATA boats; INFILE 'c:\MyRawData\Boats.dat'; INPUT Name $ 1-12 Port $ 14-20 Locomotion $ 22-26 Type $ 28-30 Price 32-36; RUN; * Tabulations with two dimensions and statistics; PROC TABULATE DATA = boats; CLASS Locomotion Type; VAR Price; TABLE Locomotion ALL, MEAN*Price*(Type ALL); TITLE 'Mean Price by Locomotion and Type'; RUN;
Section 4.14
DATA boats; INFILE 'c:\MyRawData\Boats.dat'; INPUT Name $ 1-12 Port $ 14-20 Locomotion $ 22-26 Type $ 28-30 Price 32-36; RUN; * PROC TABULATE report with options; PROC TABULATE DATA = boats FORMAT=DOLLAR9.2; CLASS Locomotion Type; VAR Price; TABLE Locomotion ALL, MEAN*Price*(Type ALL) /BOX='Full Day Excursions' MISSTEXT='none'; TITLE; RUN;
Section 4.15
DATA boats; INFILE 'c:\MyRawData\Boats.dat'; INPUT Name $ 1-12 Port $ 14-20 Locomotion $ 22-26 Type $ 28-30 Price 32-36; RUN; * Changing headers; PROC FORMAT; VALUE $typ 'cat' = 'catamaran' 'sch' = 'schooner' 'yac' = 'yacht'; RUN; PROC TABULATE DATA = boats FORMAT=DOLLAR9.2; CLASS Locomotion Type; VAR Price; FORMAT Type $typ.; TABLE Locomotion='' ALL, MEAN=''*Price='Mean Price by Type of Boat'*(Type='' ALL) /BOX='Full Day Excursions' MISSTEXT='none'; TITLE; RUN;
Section 4.16
DATA boats; INFILE 'c:\MyRawData\Boats2.dat'; INPUT Name $ 1-12 Port $ 14-20 Locomotion $ 22-26 Type $ 28-30 Price 32-36 Length 38-40; RUN; * Using the FORMAT= option in the TABLE statement; PROC TABULATE DATA = boats; CLASS Locomotion Type; VAR Price Length; TABLE Locomotion ALL, MEAN * (Price*FORMAT=DOLLAR6.2 Length*FORMAT=6.0) * (Type ALL); TITLE 'Price and Length by Type of Boat'; RUN;
Section 4.17
DATA natparks; INFILE 'c:\MyRawData\Parks.dat'; INPUT Name $ 1-21 Type $ Region $ Museums Camping; RUN; PROC REPORT DATA = natparks NOWINDOWS HEADLINE; TITLE 'Report with Character and Numeric Variables'; RUN; PROC REPORT DATA = natparks NOWINDOWS HEADLINE; COLUMN Museums Camping; TITLE 'Report with Only Numeric Variables'; RUN;
Section 4.18
DATA natparks; INFILE 'c:\MyRawData\Parks.dat'; INPUT Name $ 1-21 Type $ Region $ Museums Camping; RUN; * PROC REPORT with ORDER variable, MISSING option, and column header; PROC REPORT DATA = natparks NOWINDOWS HEADLINE MISSING; COLUMN Region Name Museums Camping; DEFINE Region / ORDER; DEFINE Camping / ANALYSIS 'Camp/Grounds'; TITLE 'National Parks and Monuments Arranged by Region'; RUN;
Section 4.19
DATA natparks; INFILE 'c:\MyRawData\Parks.dat'; INPUT Name $ 1-21 Type $ Region $ Museums Camping; RUN; * Region and Type as GROUP variables; PROC REPORT DATA = natparks NOWINDOWS HEADLINE; COLUMN Region Type Museums Camping; DEFINE Region / GROUP; DEFINE Type / GROUP; TITLE 'Summary Report with Two Group Variables'; RUN; * Region as GROUP and Type as ACROSS with sums; PROC REPORT DATA = natparks NOWINDOWS HEADLINE; COLUMN Region Type,(Museums Camping); DEFINE Region / GROUP; DEFINE Type / ACROSS; TITLE 'Summary Report with a Group and an Across Variable'; RUN;
Section 4.20
DATA natparks; INFILE 'c:\MyRawData\Parks.dat'; INPUT Name $ 1-21 Type $ Region $ Museums Camping; RUN; * PROC REPORT with breaks; PROC REPORT DATA = natparks NOWINDOWS HEADLINE; COLUMN Name Region Museums Camping; DEFINE Region / ORDER; BREAK AFTER Region / SUMMARIZE OL SKIP; RBREAK AFTER / SUMMARIZE OL SKIP; TITLE 'Detail Report with Summary Breaks'; RUN;
Section 4.21
DATA natparks; INFILE 'c:\MyRawData\Parks.dat'; INPUT Name $ 1-21 Type $ Region $ Museums Camping; RUN; *Statistics in COLUMN statement with two group variables; PROC REPORT DATA = natparks NOWINDOWS HEADLINE; COLUMN Region Type N (Museums Camping),MEAN; DEFINE Region / GROUP; DEFINE Type / GROUP; TITLE 'Statistics with Two Group Variables'; RUN; *Statistics in COLUMN statement with group and across variables; PROC REPORT DATA = natparks NOWINDOWS HEADLINE; COLUMN Region N Type,(Museums Camping),MEAN; DEFINE Region / GROUP; DEFINE Type / ACROSS; TITLE 'Statistics with a Group and Across Variable'; RUN;
Section 4.22
DATA natparks; INFILE 'c:\MyRawData\Parks.dat'; INPUT Name $ 1-21 Type $ Region $ Museums Camping; RUN; * COMPUTE new variables that are numeric and character; PROC REPORT DATA = natparks NOWINDOWS HEADLINE; COLUMN Name Region Museums Camping Facilities Note; DEFINE Museums / ANALYSIS SUM NOPRINT; DEFINE Camping / ANALYSIS SUM NOPRINT; DEFINE Facilities / COMPUTED 'Camping/and/Museums'; DEFINE Note / COMPUTED; COMPUTE Facilities; Facilities = Museums.SUM + Camping.SUM; ENDCOMP; COMPUTE Note / CHAR LENGTH = 10; IF Camping.SUM = 0 THEN Note = 'No Camping'; ENDCOMP; TITLE 'Report with Two Computed Variables'; RUN;
Section 4.23
DATA books; INFILE 'c:\MyRawData\LibraryBooks.dat'; INPUT Age BookType $ @@; RUN; *Define formats to group the data; PROC FORMAT; VALUE agegpa 0-18 = '0 to 18' 19-25 = '19 to 25' 26-49 = '26 to 49' 50-HIGH = ' 50+ '; VALUE agegpb 0-25 = '0 to 25' 26-HIGH = ' 26+ '; VALUE $typ 'bio','non','ref' = 'Non-Fiction' 'fic','mys','sci' = 'Fiction'; RUN; *Create two way table with Age grouped into four categories; PROC FREQ DATA = books; TITLE 'Patron Age by Book Type: Four Age Groups'; TABLES BookType * Age / NOPERCENT NOROW NOCOL; FORMAT Age agegpa. BookType $typ.; RUN; *Create two way table with Age grouped into two categories; PROC FREQ DATA = books; TITLE 'Patron Age by Book Type: Two Age Groups'; TABLES BookType * Age / NOPERCENT NOROW NOCOL; FORMAT Age agegpb. BookType $typ.; 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 4.2, OutputMajor Impressionist Painters Obs Name Genre Origin 1 Mary Cassatt Impressionism U 3 Edgar Degas Impressionism F 5 Claude Monet Impressionism F 6 Pierre Auguste Renoir Impressionism F F = France N = Netherlands U = USSection 4.3, Output
Whales and Sharks Obs Name Family Length 1 humpback 50.0 2 whale shark 40.0 3 basking shark 30.0 4 mako shark 12.0 5 dwarf shark 0.5 6 blue whale 100.0 7 sperm whale 60.0 8 gray whale 50.0 9 killer whale 30.0 10 beluga whale 15.0Section 4.4, Output
Candy Sales for Field Trip by Class ------------------------------------------- Class=14 -------------------------------------------- Date Candy Obs Name Returned Type Profit 1 Nathan 17612 CD 23.75 2 Matthew 17612 CD 17.50 3 Claire 17613 CD 13.75 4 Chris 17616 CD 7.50 5 Stephen 17616 CD 12.50 ----- ------ Class 75.00 ------------------------------------------- Class=21 -------------------------------------------- Date Candy Obs Name Returned Type Profit 6 Adriana 17612 MP 8.75 7 Caitlin 17615 CD 11.25 8 Ian 17615 MP 22.50 9 Anthony 17616 MP 16.25 10 Erika 17616 MP 21.25 ----- ------ Class 80.00 ====== 155.00Section 4.5, Output
Candy Sale Data Using Formats Date Candy Obs Name Returned Type Profit 1 Adriana 21MAR2008 MP $8.75 2 Nathan 21MAR2008 CD $23.75 3 Matthew 21MAR2008 CD $17.50 4 Claire 22MAR2008 CD $13.75 5 Caitlin 24MAR2008 CD $11.25 6 Ian 24MAR2008 MP $22.50 7 Chris 25MAR2008 CD $7.50 8 Anthony 25MAR2008 MP $16.25 9 Stephen 25MAR2008 CD $12.50 10 Erika 25MAR2008 MP $21.25Section 4.7, Output
Survey Results Printed with User-Defined Formats Obs Age Sex Income Color 1 Teen Male $14,000 Sunburst Yellow 2 Adult Male $65,000 Rain Cloud Gray 3 Senior Female $35,000 Sky Blue 4 Adult Male $44,000 Sunburst Yellow 5 Adult Female $83,000 Moon WhiteSection 4.8, Output
Section 4.9, Output
Section 4.10, Output
Section 4.11, Output
Section 4.12, Output
Section 4.13, Output
Section 4.14, Output
Section 4.15, Output
Section 4.16, Output
Section 4.17, Output
Section 4.18, Output
Section 4.19, Output
Section 4.20, Output
Section 4.21, Output
Section 4.22, Output
Section 4.23, Output
Type: | Sample |
Date Modified: | 2009-01-29 17:16:45 |
Date Created: | 2009-01-09 14:22:27 |
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 |