Practical and Efficient SAS Programming

Book description


Learn to write SAS programs quickly and efficiently.

Programming in SAS is flexible, but it can also be overwhelming. Many novice and experienced programmers learn how to write programs that use the DATA step and macros, but they often don’t realize that a simpler or better way can achieve the same results. In a user-friendly tutorial style, Practical and Efficient SAS® Programming: The Insider's Guide provides general SAS programming tips that use the tools available in Base SAS, including the DATA step, the SAS macro facility, and SQL.

Drawing from the author’s 30 years of SAS programming experience, this book offers self-contained sections that describe each tip or trick and present numerous examples. It therefore serves as both an easy reference for a specific question, and a useful cover-to-cover read. As a bonus, the utility programs included in the appendixes will help you simplify your programs, as well as help you develop a sleek and efficient coding style.

With this book, you will learn how to do the following:

use the DATA step, the SAS macro facility, SQL, and other Base SAS tools more efficiently

choose the best tool for a task

use lookup tables

simulate recursion with macros

read metadata with the DATA step

create your own programming style in order to write programs that are easily maintained

Using this book, SAS programmers of all levels will discover new techniques to help them write programs quickly and efficiently.

Table of contents

  1. About This Book
  2. About The Author
  3. Acknowledgments
  4. Chapter 1: My Favorite Functions
  5. Introduction
  6. Concatenating Strings
    1. Converting Numbers to Characters
    2. Adding Delimiters
    3. Using the OF Shortcut
  7. Removing Leading and Trailing Spaces
  8. Finding Non-Blank Values
  9. Creating Datetime Values
  10. Creating Macro Variables
  11. Finding Words
  12. Counting Words
  13. Replacing Substrings
  14. Using %SYSFUNC() to Run DATA Step Functions
  15. Chapter 2: Data Tables
  16. Introduction
  17. Copying Variable Attributes
  18. Reading Data with a SET Statement
    1. Concatenating Tables
    2. Interleaving Tables
    3. Using Multiple SET Statements
  19. Determining Which Table a Record Is From
  20. Using PROC SQL
    1. Choosing to Use PROC SQL
    2. Joining
    3. Using a Subquery
    4. Using a Correlated Subquery
  21. Using Lookup Tables
    1. Using a Format
    2. Using a Join
    3. Using a SET Statement With KEY=
    4. Using Hash Tables
  22. Updating Data In Place
    1. Using PROC SQL
    2. Using the MODIFY Statement
    3. Using PROC APPEND
  23. Finding Records
    1. Determining Whether a Table Exists
    2. Getting the Number of Records
    3. Verifying That a Table Has Records
  24. Re-creating Indexes
  25. Chapter 3: The Operating System
  26. Introduction
  27. Checking the Operating System
  28. Running Operating System Commands
    1. Using the X Statement
    2. Using the SYSTEM() Function
    3. Using a FILENAME Pipe
  29. Working with the File System
    1. Creating and Deleting Directories
    2. Working with Files
  30. Reading and Writing External Files
    1. Using the $VARYING. Format and Informat
    2. Using the FILEVAR= Option
    3. Reading Date and Time Values
  31. Creating a CSV File from a Data Table
  32. Reading a CSV File with Embedded Line Feeds
  33. Chapter 4: The Macro Facility
  34. Introduction
  35. Understanding Macro Variables
    1. Using the “Dot” in Macro Variable Names
    2. Determining How Many &s to Use
    3. Understanding Quotation Marks
    4. Using Macro Quoting
    5. Unquoting
    6. Forcing Single Quotation Marks
  36. Writing Macros
    1. Using Autocall Macros
    2. Determining When to Write a Macro
    3. Wrapping Long Lines of Code
    4. Using the IN Operator
    5. Testing for Blanks
    6. Validating Parameters
    7. Creating Macro Functions
  37. Chapter 5: SAS Programming
  38. Introduction
  39. Using the ABORT Statement
  40. Updating Option Values
  41. Getting Information from SASHELP Views
  42. Creating a Unique Key with PROC SQL
  43. Setting a Boolean
  44. Accumulating Values
  45. Replacing a Substring
  46. Using Data Values Tables to Create and Run Code
    1. Using Macro Variable Arrays
    2. Creating and Including Code
    3. Using CALL EXECUTE
  47. Taking Control of DATA Step Processing
    1. Branching
    2. Returning
    3. Deleting
    4. Subsetting
    5. Stopping
    6. Aborting
    7. Continuing
    8. Leaving
  48. Figuring Out Where You Are
    1. Counting Iterations
    2. Finding the End
    3. Finding Group Beginnings and Endings
  49. Chapter 6: Application Development
  50. Introduction
  51. Using Comments
    1. Choosing a Style
    2. Commenting Out Chunks of Code
  52. Dealing with Notes, Warnings, and Errors
    1. Getting Rid of Common Notes, Warnings, and Errors
    2. Creating Custom Error and Warning Messages
    3. Capturing Error and Warning Messages
  53. Protecting Your Password
    1. Encoding a Password
    2. Storing a Password
    3. Hiding a Password
  54. Using the PUT, PUTLOG, and %PUT statements
    1. Debugging with PUTLOG
    2. Using the VAR= Syntax
    3. Using Shortcuts
    4. Getting Rid of Unneeded Spaces
    5. Displaying a Macro Value in the SAS Log
    6. Using Macro Shortcuts
  55. Chapter 7: Advanced Tasks
  56. Introduction
  57. Sending Email
    1. A Single Message
    2. Multiple Messages
  58. Running Code in Parallel
    1. Using MPCONNECT
    2. Striping Data
  59. Simulating Recursion
  60. Reading Metadata
  61. Using the XML LIBNAME Engine
  62. Appendix A: Utility Macros
  63. Introduction
  64. Deleting Tables
  65. Getting the Number of Records
  66. Getting a Library’s Engine Name
  67. Getting a Variable Keep List
  68. Making ATTRIB Statements
  69. Making a Basic Format
  70. Making a Directory Path
  71. Creating Macro Variables from SYSPARM
  72. Setting Log Options
  73. Displaying Macro Notes for Debugging
  74. Refreshing Autocall Macros
  75. Appendix B: Display Manager
  76. Introduction
  77. Using the Enhanced Editor
    1. Indenting Your Code
    2. Commenting Out a Section of Code
    3. Converting a String to Uppercase or Lowercase
    4. Removing Excessive White Space
    5. Opening a New Enhanced Editor Window
  78. Using the Program Editor
    1. Customizing Function Keys
    2. Setting Options
    3. Using Line Commands
    4. Working with the Recall Stack
  79. Handling Unbalanced Quotation Marks
  80. Appendix C: Coding Style
  81. Introduction
  82. Indenting
  83. Aligning
  84. Handling Line Lengths
  85. Using Capital Letters (or Not)
  86. Naming
  87. Coding with Style
  88. References
  89. Index

Product information

  • Title: Practical and Efficient SAS Programming
  • Author(s): Martha Messineo
  • Release date: September 2017
  • Publisher(s): SAS Institute
  • ISBN: 9781635262223