SAS - SAS Certification Prep Guide. Base Programming for SAS9 [5th ed.]-SAS (2018).pdf - SAS Certification Prep Guide Base Programming for SAS 9 Fifth

SAS - SAS Certification Prep Guide. Base Programming for SAS9 [5th ed.]-SAS (2018).pdf

This preview shows page 1 out of 375 pages.

Unformatted text preview: SAS Certification Prep Guide: Base Programming for SAS 9, Fifth Edition SAS® Documentation August 23, 2018 SAS Institute Inc. 2018 SAS Certification Prep Guide: Base Programming for SAS9 Fifth Edition. Cary, NC: SAS Institute Inc. SAS® Certification Prep Guide: Base Programming for SAS®9, Fifth Edition Copyright © 2018, SAS Institute Inc., Cary, NC, USA ISBN 978-1-63526-994-9 (Hard copy) ISBN 978-1-63526-991-8 (Epub) ISBN 978-1-63526-992-5 (Mobi) ISBN 978-1-63526-993-2 (PDF) Produced in the United States of America SAS Institute Inc., SAS Campus Drive, Cary, NC 27513-2414 September 2018 Contents How to Prepare for the SAS Base Programming for SAS®9 Exam . . . . . . . . . . . . . . . . vii Accessibility Features of the SAS Certification Prep Guide . . . . . . . . . . . . . . . . . . . . . . xi Chapter 1 • Setting Up Practice Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Accessing Your Practice Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 2 • Basic Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 The Basics of the SAS Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 SAS Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Referencing SAS Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Chapter 3 • Accessing Your Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 SAS Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Viewing SAS Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Chapter 4 • Creating SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Referencing an External Data File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 The IMPORT Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Reading and Verifying Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Using the Imported Data in a DATA Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Reading a Single SAS Data Set to Create Another . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Reading Microsoft Excel Data with the XLSX Engine . . . . . . . . . . . . . . . . . . . . . . . . . 47 Creating Excel Worksheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Writing Observations Explicitly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Chapter 5 • Identifying and Correcting SAS Language Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Correcting Common Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Chapter 6 • Creating Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Creating a Basic Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Selecting Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Identifying Observations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Sorting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Generating Column Totals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Specifying Titles and Footnotes in Procedure Output . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Assigning Descriptive Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Using Permanently Assigned Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Chapter 7 • Understanding DATA Step Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 How SAS Processes Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Compilation Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 Execution Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Debugging a DATA Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Testing Your Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 120 125 126 Chapter 8 • BY-Group Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Preprocessing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 FIRST. and LAST. DATA Step Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Chapter 9 • Creating and Managing Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 Creating Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Modifying Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 Specifying Lengths for Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Subsetting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Chapter 10 • Combining SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 How to Prepare Your Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 Methods of Combining SAS Data Sets: The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 One-to-One Reading: Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Concatenating: Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 Match-Merging: Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Match-Merge Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 Renaming Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 Excluding Unmatched Observations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 Chapter 11 • Processing Data with DO Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 The Basics of DO Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 Constructing DO Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 Nesting DO Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 Iteratively Processing Observations from a Data Set . . . . . . . . . . . . . . . . . . . . . . . . . . 203 Conditionally Executing DO Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 Chapter 12 • SAS Formats and Informats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 Applying SAS Formats and Informats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 The FORMAT Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 Defining a Unique Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 Associating User-Defined Formats with Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 Chapter 13 • SAS Date, Time, and Datetime Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 SAS Date and Time Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 Reading Dates and Times with Informats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Example: Using Dates and Times in Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Displaying Date and Time Values with Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 Chapter 14 • Using Functions to Manipulate Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 The Basics of SAS Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 SAS Functions Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 Converting Data with Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 Manipulating SAS Date Values with Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 Modifying Character Values with Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Modifying Numeric Values with Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Nesting SAS Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 287 290 291 Chapter 15 • Producing Descriptive Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 The MEANS Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 The FREQ Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 Chapter 16 • Creating Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 The Output Delivery System (ODS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324 Creating HTML Output with ODS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326 Creating PDF Output with ODS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 Creating RTF Output with ODS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340 Creating EXCEL Output with ODS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342 Chapter Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 Appendix 1 • Quiz Answer Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 Chapter 2: Basic Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 Chapter 3: Accessing Your Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 Chapter 4: Creating SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 Chapter 5: Identifying and Correcting SAS Language Errors . . . . . . . . . . . . . . . . . . . 350 Chapter 6: Creating Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351 Chapter 7: Understanding DATA Step Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 Chapter 8: BY-Group Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354 Chapter 9: Creating and Managing Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354 Chapter 10: Combining SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356 Chapter 11: Processing Data with DO Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357 Chapter 12: SAS Formats and Informats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358 Chapter 13: SAS Date, Time, and Datetime Values . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 Chapter 14: Using Functions to Manipulate Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360 Chapter 15: Producing Descriptive Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360 Chapter 16: Creating Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363 How to Prepare for the SAS Base Programming for SAS®9 Exam Requirements and Details Requirements To complete examples in this book, you must have access to SAS windowing environment, SAS Enterprise Guide, or SAS Studio. Exam Objectives and Updates to This Book The current exam objectives and a list of any updates to this book are available at . Exam objectives are subject to change. Take a Practice Exam Practice exams are available for purchase through SAS and Pearson VUE. For more information about practice exams, see . Registering for the Exam To register for the SAS Base Programming for SAS®9 exam, see the SAS Global Certification website at . Additional Resources for Learning SAS Programming From SAS Software Help • SAS ®9: Select Help ð SAS Help and Documentation. • SAS Enterprise Guide: Select Help ð SAS Enterprise Guide Help. • SAS Studio: Select the Help icon Documentation . • SAS ®9: Select Help ð SAS Help and Documentation. • SAS Enterprise Guide: Access online documentation on the web. • SAS Studio: Select the Help icon and then click Help. On the Web Base SAS Glossary support.sas.com/baseglossary Bookstore Certification Communities communities.sas.com Knowledge Base support.sas.com/notes Learning Center and click Learn. Then select Get Started with SAS. SAS Documentation support.sas.com/documentation documentation.sas.com SAS Global Academic Program and click Learn. Then select For Students and Educators. SAS OnDemand support.sas.com/ondemand/ Syntax Quick Reference Guide support.sas.com/content/dam/SAS/support/en/ books/data/base-syntax-ref.pdf Training Technical Support support.sas.com. Then select Technical Support. Syntax Conventions In this book, SAS syntax looks like this example: DATA output-SAS-data-set (DROP=variables(s) | KEEP=variables(s)); SET SAS-data-set <options>; BY variable(s); RUN; Here are the conventions that are used in the example: • DATA, DROP=, KEEP=, SET, BY, and RUN are in uppercase bold because they must be spelled as shown. • output-SAS-data-set, variable(s), SAS-data-set, and options are in italics because each represents a value that you supply. • <options> is enclosed in angle brackets because it is optional syntax. • DROP= and KEEP= are separated by a vertical bar ( | ) to indicate that they are mutually exclusive. The example syntax that is shown in this book includes only what you need to know in order to prepare for the certification exam. For complete syntax, see the appropriate SAS reference guide. Accessibility Features of the SAS Certification Prep Guide Overview The SAS Certification Prep Guide: Base Programming for SAS®9 is a test preparation document that uses the following environments and products: • SAS windowing environment • SAS Enterprise Guide • SAS Studio or SAS University Edition Accessibility Documentation Help The following table contains accessibility information for the listed products: Accessibility Documentation Links Product or Environment Where to Find Accessibility Documentation Base SAS (Microsoft Windows, UNIX, and z/OS) support.sas.com/baseaccess SAS Enterprise Guide support.sas.com/documentation/onlinedoc/ guide/index.html SAS Studio support.sas.com/studioaccess Documentation Format Contact [email protected] if you need this document in an alternative digital format. 1 Chapter 1 Setting Up Practice Data Accessing Your Practice Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Practice Data ZIP File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Accessing Your Practice Data Requirements To complete examples in this book, you must have access to SAS Studio, SAS Enterprise Guide, or the SAS windowing environment. Practice Data ZIP File The ZIP file includes SAS data sets, Microsoft Excel workbooks (.xlsx), CSV files (.csv), and TXT files (.txt) that are used in examples in this book. To access these files and create your practice data, follow the instructions below. Instructions 1. Navigate to support.sas.com/content/dam/SAS/support/en/books/data/base-guidepractice-data.zip, download and save the practice data ZIP file. 2. Unzip the file and save it ...
View Full Document

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture