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 7.2
%LET flowertype = Ginger; * Read the data and subset with a macro variable; DATA flowersales; INFILE 'c:\MyRawData\TropicalSales.dat'; INPUT CustomerID $4. @6 SaleDate MMDDYY10. @17 Variety $9. Quantity; IF Variety = "&flowertype"; RUN; * Print the report using a macro variable; PROC PRINT DATA = flowersales; FORMAT SaleDate WORDDATE18.; TITLE "Sales of &flowertype"; RUN;
Section 7.3
* Macro to print 5 largest sales; %MACRO sample; PROC SORT DATA = flowersales; BY DESCENDING Quantity; RUN; PROC PRINT DATA = flowersales (OBS = 5); FORMAT SaleDate WORDDATE18.; TITLE 'Five Largest Sales'; RUN; %MEND sample; * Read the flower sales data; DATA flowersales; INFILE 'c:\MyRawData\TropicalSales.dat'; INPUT CustomerID $4. @6 SaleDate MMDDYY10. @17 Variety $9. Quantity; RUN; * Invoke the macro; %sample
Section 7.4
* Macro with parameters; %MACRO select(customer=,sortvar=); PROC SORT DATA = flowersales OUT = salesout; BY &sortvar; WHERE CustomerID = "&customer"; RUN; PROC PRINT DATA = salesout; FORMAT SaleDate WORDDATE18.; TITLE1 "Orders for Customer Number &customer"; TITLE2 "Sorted by &sortvar"; RUN; %MEND select; * Read all the flower sales data; DATA flowersales; INFILE 'c:\MyRawData\TropicalSales.dat'; INPUT CustomerID $4. @6 SaleDate MMDDYY10. @17 Variety $9. Quantity; RUN; *Invoke the macro; %select(customer = 356W, sortvar = Quantity) %select(customer = 240W, sortvar = Variety)
Section 7.5
%MACRO dailyreports; %IF &SYSDAY = Monday %THEN %DO; PROC PRINT DATA = flowersales; FORMAT SaleDate WORDDATE18.; TITLE 'Monday Report: Current Flower Sales'; RUN; %END; %ELSE %IF &SYSDAY = Tuesday %THEN %DO; PROC MEANS DATA = flowersales MEAN MIN MAX; CLASS Variety; VAR Quantity; TITLE 'Tuesday Report: Summary of Flower Sales'; RUN; %END; %MEND dailyreports; DATA flowersales; INFILE 'c:\MyRawData\TropicalSales.dat'; INPUT CustomerID $4. @6 SaleDate MMDDYY10. @17 Variety $9. Quantity; RUN; %dailyreports DATA flowersales; INFILE 'c:\MyRawData\TropicalSales.dat'; INPUT CustomerID $ @6 SaleDate MMDDYY10. @17 Variety $9. Quantity; RUN; PROC MEANS DATA = flowersales MEAN MIN MAX; CLASS Variety; VAR Quantity; TITLE 'Tuesday Report: Summary of Flower Sales'; RUN;
Section 7.6
* Read the raw data; DATA flowersales; INFILE 'c:\MySASLib\TropicalSales.dat'; INPUT CustomerID $4. @6 SaleDate MMDDYY10. @17 Variety $9. Quantity; PROC SORT DATA = flowersales; BY DESCENDING Quantity; RUN; * Find biggest order and pass the customer id to a macro variable; DATA _NULL_; SET flowersales; IF _N_ = 1 THEN CALL SYMPUT("selectedcustomer",CustomerID); ELSE STOP; RUN; PROC PRINT DATA = flowersales; WHERE CustomerID = "&selectedcustomer"; FORMAT SaleDate WORDDATE18.; TITLE "Customer &selectedcustomer Had the Single Largest Order"; 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 7.2, Output
Sales of Ginger Customer Obs ID SaleDate Variety Quantity 1 240W February 7, 2008 Ginger 120 2 188R February 11, 2008 Ginger 24 3 356W February 12, 2008 Ginger 240Section 7.3, Output
Five Largest Sales Customer Obs ID SaleDate Variety Quantity 1 356W February 8, 2008 Anthurium 300 2 356W February 12, 2008 Ginger 240 3 240W February 7, 2008 Protea 180 4 240W February 7, 2008 Ginger 120 5 356W February 8, 2008 Heliconia 60Section 7.4, Output
Orders for Customer Number 356W Sorted by Quantity Customer Obs ID SaleDate Variety Quantity 1 356W February 8, 2008 Heliconia 60 2 356W February 12, 2008 Ginger 240 3 356W February 8, 2008 Anthurium 300 Orders for Customer Number 240W Sorted by Variety Customer Obs ID SaleDate Variety Quantity 1 240W February 7, 2008 Ginger 120 2 240W February 12, 2008 Heliconia 48 3 240W February 7, 2008 Protea 180 4 240W February 12, 2008 Protea 48Section 7.5, Output
Section 7.6, Output
Customer 356W Had the Single Largest Order Customer Obs ID SaleDate Variety Quantity 1 356W February 8, 2008 Anthurium 300 2 356W February 12, 2008 Ginger 240 5 356W February 8, 2008 Heliconia 60
Type: | Sample |
Date Modified: | 2009-01-29 17:19:35 |
Date Created: | 2009-01-27 10:56:36 |
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 |