SAS® Workshop
Total Page:16
File Type:pdf, Size:1020Kb
SAS® Workshop Manitoba Centre for Health Policy University of Manitoba Input and Development by: Charles Burchill, Heather Prior, Wendy Au, Jen Bodnarchuk, Randy Walld Shelley Derksen, Jill MacGregor, Ruth-Ann Soodeen, and Ruth Bond September 2018 - 1 - - 2 - Table of Contents Outline ..................................................................................................................................................................................................... 5 Resource Books ................................................................................................................................................................................. 6 CD Content ........................................................................................................................................................................................ 6 SAS University Edition ..................................................................................................................................................................... 6 Full Version of SAS (UofM Students and Staff only)........................................................................................................................ 6 Data Use Agreement................................................................................................................................................................................ 8 Overview ................................................................................................................................................................................................. 9 What Is SAS ...................................................................................................................................................................................... 9 SAS Interface(s) ................................................................................................................................................................................ 9 SAS/Studio .............................................................................................................................................................................................. 9 SAS Studio Environment ................................................................................................................................................................. 11 SAS Data Structure. .............................................................................................................................................................................. 13 Why Programming? ......................................................................................................................................................................... 13 Programming Structure .................................................................................................................................................................... 14 Structured SAS Code Suggestions. ........................................................................................................................................................ 15 General suggestions. ........................................................................................................................................................................ 15 Data step .......................................................................................................................................................................................... 16 Macro code ...................................................................................................................................................................................... 17 Procedures ....................................................................................................................................................................................... 17 Comments........................................................................................................................................................................................ 17 Test code ......................................................................................................................................................................................... 17 SAS Programming Examples ................................................................................................................................................................ 19 Example 1 ........................................................................................................................................................................................ 19 * Part I: Viewing Data ; ............................................................................................................................................... 20 * Part II: Exploring the data; .................................................................................................................................. 21 Example 2 ........................................................................................................................................................................................ 23 * Part I: Import Data, Use of Formats and Labels ; ....................................................................................... 23 * Part II: Sub-setting & Manipulating data, & Creating Variables; ...................................................... 25 * Part III: Getting Data Out of SAS through PROC EXPORT and ODS ; .................................................... 28 Example 3 ........................................................................................................................................................................................ 31 * Part I: SAS Options (printing); ........................................................................................................................... 31 * Part II: Sorting Data with Proc Sort;............................................................................................................... 31 * Part III: Setting or Concatenation of Data ; ............................................................................................... 32 * Part IV. Merging or adding variables;............................................................................................................... 33 * Part V: Use of Put() with formats for creating variables; ................................................................... 35 * Part VI: Type Conversions put/input ;............................................................................................................... 37 Example 4 ........................................................................................................................................................................................ 40 * Part I: By group processing for Longitudinal Data ; ................................................................................ 40 * Part II. Groups of Variables & Array processing; ....................................................................................... 43 * SESSION 5. ; ................................................................................................................................................................................ 46 * Part I: Date time processing ; .............................................................................................................................. 46 * Part II: SQL Processing ; ........................................................................................................................................ 48 Practice Questions ................................................................................................................................................................................. 54 SAS Workshop Practice Questions #1 ............................................................................................................................................. 54 SAS Workshop Practice Questions #2 ............................................................................................................................................. 55 SAS Workshop Practice Questions #3 ............................................................................................................................................. 57 SAS Workshop Practice Questions #4 ............................................................................................................................................. 58 SAS Workshop Practice Questions #5 ............................................................................................................................................. 60 Data Dictionaries ................................................................................................................................................................................... 62 MCHP Training and Research Resource ............................................................................................................................................... 62 Height/Weight Dictionary ............................................................................................................................................................... 62 Hospital Dictionary ........................................................................................................................................................................