You are previewing The Little SAS® Book: A Primer, Fourth Edition.
O'Reilly logo
The Little SAS® Book: A Primer, Fourth Edition

Book Description

Now in its fourth edition, The Little SAS Book is a classic, helping many people learn SAS programming. Authors Lora Delwiche and Susan Slaughter's friendly, easy-to-read writing style gently introduces readers to the most commonly used features of the SAS language. Topics include basic SAS concepts such as the DATA and PROC steps, inputting data, modifying and combining data sets, summarizing data, producing reports, and debugging SAS programs. Each topic is presented in a self-contained two-page layout complete with examples and graphics. This clear and concise format enables new users to get up and running quickly, while the examples allow readers to type in the program and see it work! New topics in the fourth edition include ODS Graphics for statistical procedures, PROC SGPLOT for graphics, creating new variables in PROC REPORT with a COMPUTE block, WHERE= data set option, SORTSEQ=LINGUISTIC option in PROC SORT, and more functions, including ANYALPHA, CAT, PROPCASE, and YRDIF.

Table of Contents

  1. Copyright
  2. Acknowledgments
  3. Introducing SAS Software
  4. About This Book
  5. What's New
    1. ODS Graphics (new with SAS 9.2)
    2. Other features new with SAS 9.2
    3. Also new with this edition
  6. 1
  7. 1. Getting Started Using SAS Software
    1. 1.1. The SAS Language
    2. 1.2. SAS Data Sets
    3. 1.3. The Two Parts of a SAS Program
    4. 1.4. The DATA Step's Built-in Loop
    5. 1.5. Choosing a Mode for Submitting SAS Programs
    6. 1.6. Windows and Commands in the SAS Windowing Environment
      1. The SAS Windows
      2. The SAS Commands
    7. 1.7. Submitting a Program in the SAS Windowing Environment
    8. 1.8. Reading the SAS Log
    9. 1.9. Viewing Your Results in the Output Window
    10. 1.10. Creating HTML Output
    11. 1.11. SAS Data Libraries
    12. 1.12. Viewing Data Sets in the Viewtable Window
    13. 1.13. Viewing the Properties of Data Sets with SAS Explorer
    14. 1.14. Using SAS System Options
  8. 2
  9. 2. Getting Your Data into SAS
    1. 2.1. Methods for Getting Your Data into SAS
    2. 2.2. Entering Data with the Viewtable Window
    3. 2.3. Reading Files with the Import Wizard
    4. 2.4. Telling SAS Where to Find Your Raw Data
    5. 2.5. Reading Raw Data Separated by Spaces
    6. 2.6. Reading Raw Data Arranged in Columns
    7. 2.7. Reading Raw Data Not in Standard Format
    8. 2.8. Selected Informats
    9. 2.9. Mixing Input Styles
    10. 2.10. Reading Messy Raw Data
    11. 2.11. Reading Multiple Lines of Raw Data per Observation
    12. 2.12. Reading Multiple Observations per Line of Raw Data
    13. 2.13. Reading Part of a Raw Data File
    14. 2.14. Controlling Input with Options in the INFILE Statement
    15. 2.15. Reading Delimited Files with the DATA Step
    16. 2.16. Reading Delimited Files with the IMPORT Procedure
    17. 2.17. Reading PC Files with the IMPORT Procedure
    18. 2.18. Reading PC Files with DDE
    19. 2.19. Temporary versus Permanent SAS Data Sets
    20. 2.20. Using Permanent SAS Data Sets with LIBNAME Statements
    21. 2.21. Using Permanent SAS Data Sets by Direct Referencing
    22. 2.22. Listing the Contents of a SAS Data Set
  10. 3
  11. 3. Working with Your Data
    1. 3.1. Creating and Redefining Variables
    2. 3.2. Using SAS Functions
    3. 3.3. Selected SAS Character Functions
    4. 3.4. Selected SAS Numeric Function
    5. 3.5. Using IF-THEN Statements
    6. 3.6. Grouping Observations with IF-THEN/ELSE Statements
    7. 3.7. Subsetting Your Data
    8. 3.8. Working with SAS Dates
    9. 3.9. Selected Date Informats, Functions, and Formats
    10. 3.10. Using the RETAIN and Sum Statements
    11. 3.11. Simplifying Programs with Arrays
    12. 3.12. Using Shortcuts for Lists of Variable Names
  12. 4
  13. 4. Sorting, Printing, and Summarizing Your Data
    1. 4.1. Using SAS Procedures
    2. 4.2. Subsetting in Procedures with the WHERE Statement
    3. 4.3. Sorting Your Data with PROC SORT
    4. 4.4. Printing Your Data with PROC PRINT
    5. 4.5. Changing the Appearance of Printed Values with Formats
    6. 4.6. Selected Standard Formats
    7. 4.7. Creating Your Own Formats Using PROC FORMAT
    8. 4.8. Writing Simple Custom Reports
    9. 4.9. Summarizing Your Data Using PROC MEANS
    10. 4.10. Writing Summary Statistics to a SAS Data Set
    11. 4.11. Counting Your Data with PROC FREQ
    12. 4.12. Producing Tabular Reports with PROC TABULATE
    13. 4.13. Adding Statistics to PROC TABULATE Output
    14. 4.14. Enhancing the Appearance of PROC TABULATE Output
    15. 4.15. Changing Headers in PROC TABULATE Output
    16. 4.16. Specifying Multiple Formats for Data Cells in PROC TABULATE Output
    17. 4.17. Producing Simple Output with PROC REPORT
    18. 4.18. Using DEFINE Statements in PROC REPORT
    19. 4.19. Creating Summary Reports with PROC REPORT
    20. 4.20. Adding Summary Breaks to PROC REPORT Output
    21. 4.21. Adding Statistics to PROC REPORT Output
    22. 4.22. Adding Computed Variables to PROC REPORT Output
    23. 4.23. Grouping Data in Procedures with User-Defined Formats
  14. 5
  15. 5. Enhancing Your Output with ODS
    1. 5.1. Concepts of the Output Delivery System
    2. 5.2. Tracing and Selecting Procedure Output
    3. 5.3. Creating SAS Data Sets from Procedure Output
    4. 5.4. Using ODS Statements to Create HTML Output
    5. 5.5. Using ODS Statements to Create RTF Output
    6. 5.6. Using ODS Statements to Create PRINTER Output
    7. 5.7. Customizing Titles and Footnotes
    8. 5.8. Customizing PROC PRINT Output with the STYLE= Option
    9. 5.9. Customizing PROC REPORT Output with the STYLE= Option
    10. 5.10. Customizing PROC TABULATE Output with the STYLE= Option
    11. 5.11. Adding Traffic-Lighting to Your Output
    12. 5.12. Selected Style Attributes
  16. 6
  17. 6. Modifying and Combining SASData Sets
    1. 6.1. Modifying a Data Set Using the SET Statement
    2. 6.2. Stacking Data Sets Using the SET Statement
    3. 6.3. Interleaving Data Sets Using the SET Statement
    4. 6.4. Combining Data Sets Using a One-to-One Match Merge
    5. 6.5. Combining Data Sets Using a One-to-Many Match Merge
    6. 6.6. Merging Summary Statistics with the Original Data
    7. 6.7. Combining a Grand Total with the Original Data
    8. 6.8. Updating a Master Data Set with Transactions
    9. 6.9. Writing Multiple Data Sets Using the OUTPUT Statement
    10. 6.10. Making Several Observations from One Using the OUTPUT Statement
    11. 6.11. Using SAS Data Set Options
    12. 6.12. Tracking and Selecting Observations with the IN= Option
    13. 6.13. Selecting Observations with the WHERE= Option
    14. 6.14. Changing Observations to Variables Using PROC TRANSPOSE
    15. 6.15. Using SAS Automatic Variables
  18. 7
  19. 7. Writing Flexible Code with the SAS Macro Facility
    1. 7.1. Macro Concepts
    2. 7.2. Substituting Text with Macro Variables
    3. 7.3. Creating Modular Code with Macros
    4. 7.4. Adding Parameters to Macros
    5. 7.5. Writing Macros with Conditional Logic
    6. 7.6. Writing Data-Driven Programs with CALL SYMPUT
    7. 7.7. Debugging Macro Errors
  20. 8
  21. 8. Using Basic Graphical and Statistical Procedures
    1. 8.1. Concepts of ODS Graphics
    2. 8.2. Creating Bar Charts with PROC SGPLOT
    3. 8.3. Creating Histograms and Box Plots with PROC SGPLOT
    4. 8.4. Creating Scatter Plots with PROC SGPLOT
    5. 8.5. Creating Series Plots with PROC SGPLOT
    6. 8.6. Creating Fitted Curves with PROC SGPLOT
    7. 8.7. Examining the Distribution of Data with PROC UNIVARIATE
    8. 8.8. Creating Statistical Graphics with PROC UNIVARIATE
    9. 8.9. Producing Statistics with PROC MEANS
    10. 8.10. Testing Categorical Data with PROC FREQ
    11. 8.11. Creating Statistical Graphics with PROC FREQ
    12. 8.12. Examining Correlations with PROC CORR
    13. 8.13. Creating Statistical Graphics with PROC CORR
    14. 8.14. Using PROC REG for Simple Regression Analysis
    15. 8.15. Creating Statistical Graphics with PROC REG
    16. 8.16. Using PROC ANOVA for One-Way Analysis of Variance
    17. 8.17. Reading the Output of PROC ANOVA
  22. 9
  23. 9. Exporting Your Data
    1. 9.1. Methods for Exporting Your Data
    2. 9.2. Writing Files Using the Export Wizard
    3. 9.3. Writing Delimited Files with the EXPORT Procedure
    4. 9.4. Writing PC Files with the EXPORT Procedure
    5. 9.5. Writing Raw Data Files with the DATA Step
    6. 9.6. Writing Delimited and HTML Files Using ODS
    7. 9.7. Sharing SAS Data Sets with Other Types of Computers
  24. 10
  25. 10. Debugging Your SAS Programs
    1. 10.1. Writing SAS Programs That Work
    2. 10.2. Fixing Programs That Don't Work
    3. 10.3. Searching for the Missing Semicolon
    4. 10.4. Note: INPUT Statement Reached Past the End of the Line
    5. 10.5. Note: Lost Card
    6. 10.6. Note: Invalid Data
    7. 10.7. Note: Missing Values Were Generated
    8. 10.8. Note: Numeric Values Have Been Converted to Character (or Vice Versa)
    9. 10.9. DATA Step Produces Wrong Results but No Error Message
    10. 10.10. The DATA Step Debugger
    11. 10.11. Error: Invalid Option, Error: The Option Is Not Recognized, or Error: Statement Is Not Valid
    12. 10.12. Note: Variable Is Uninitialized or Error: Variable Not Found
    13. 10.13. SAS Truncates a Character Variable
    14. 10.14. SAS Stops in the Middle of a Job
    15. 10.15. SAS Runs Out of Memory or Disk Space
  26. I. APPENDICES
    1. A. Where to Go from Here
      1. The SAS Customer Support Web Site
      2. SAS Help and Documentation
      3. Books Offered by SAS Press
      4. SAS Training Courses
      5. SAS User Groups
      6. sasCommunity.org
      7. sascom magazine and Electronic Newsletters
      8. SAS-L
      9. SAS Technical Support
    2. B. Coming to SAS from SPSS
    3. C. Coming to SAS from a Programming Language
    4. D. Coming to SAS from SQL