Cody's Collection of Popular SAS Programming Tasks and How to Tackle Them

Book description


Cody's Collection of Popular SAS Programming Tasks and How to Tackle Them presents often-used programming tasks that readers can either use as presented or modify to fit their own programs, all in one handy volume. Esteemed author and SAS expert Ron Cody covers such topics as character to numeric conversion, automatic detection of numeric errors, combining summary data with detail data, restructuring a data set, grouping values using several innovative methods, performing an operation on all character or all numeric variables in a SAS data set, and much more! SAS users of all levels interested in improving their programming skills will benefit from this easy-to-follow collection of tasks.

This book is part of the SAS Press program.

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Contents
  5. List of Programs
  6. About this Book
  7. About the Author
  8. Acknowledgments
  9. Chapter 1 - Tasks Involving Conversion: Character to Numeric, Specific Values to Missing, and Changing Case
    1. Introduction
    2. Task: Converting character values to numeric values
    3. Task: Converting character values to numeric values using a macro
    4. Task: Converting a specific value such as 999 to a missing value for all numeric variables in a SAS data set
    5. Task: Converting a specific value such as 'NA' to a missing value for all character variables in a SAS data set
    6. Task: Changing all character values to either uppercase, lowercase, or proper case
    7. Task: Reading a numeric value that contains units such as Lbs. or Kgs. in the value
    8. Task: Solving part of the previous task using a Perl regular expression
    9. Conclusion
  10. Chapter 2 - Grouping Data
    1. Introduction
    2. Task: Grouping values using IF-THEN-ELSE statements
    3. Task: Grouping values using user-defined formats
    4. Task: Creating groups using PROC RANK
    5. Conclusion
  11. Chapter 3 - Summarizing Data
    1. Introduction
    2. Task: Using PROC MEANS to create a data set containing summary information
    3. Task: Computing the mean of a variable broken down by values of another variable: Using a BY variable
    4. Task: Computing the mean of a variable broken down by values of another variable: Using a CLASS statement
    5. Task: Have PROC MEANS name the variables in the output data set automatically (the AUTONAME option)
    6. Task: Creating multiple output data sets from PROC MEANS, each with a different combination of CLASS variables
    7. Task: Combining summary information (a single mean) with detail data: Using a conditional SET statement.
    8. Task: Combining summary information (a single mean) with detail data: Using PROC SQL
    9. Task: Combining summary information (a single mean) with detail data: Using PROC SQL without using PROC MEANS
    10. Task: Combining summary information (a single mean) with detail data: Using a macro variable
    11. Task: Combining summary data with detail data—for each category of a BY variable.
    12. Conclusion.
  12. Chapter 4 - Combining and Updating SAS Data Sets
    1. Introduction
    2. Task: Concatenating two SAS data sets—Using a SET statement
    3. Task: Concatenating two SAS data sets—Using PROC APPEND
    4. Task: Concatenating two SAS data sets with character variables of different lengths.
    5. Task: Concatenating two SAS data sets that contain character variables of different lengths and controlling the length of the character variables
    6. Task: Developing a macro to concatenate two SAS data sets that contain character variables of different lengths
    7. Task: Updating a SAS data set using a transaction data set
    8. Task: Using a MODIFY statement to update a master file from a transaction file
    9. Task: Updating several variables using a transaction file created with an INPUT method called named input
    10. Task: Matching names from two SAS data sets where the names may not be spelled the same (fuzzy merge)
    11. Conclusion
  13. Chapter 5 - Creating Formats from SAS Data Sets
    1. Introduction
    2. Task: Using a SAS data set to create a format (by creating a control data set)
    3. Task: Adding new format values to an existing format
    4. Conclusion
  14. Chapter 6 - Table Lookup Techniques
    1. Introduction
    2. Task: Performing a one-way table lookup using a MERGE statement
    3. Task: Performing a one-way table lookup using user-defined informats
    4. Task: Creating an INFORMAT using a control data set
    5. Task: Performing a one-way table lookup using a temporary array
    6. Task: Performing a two-way table lookup using a temporary array
    7. Conclusion
  15. Chapter 7 - Restructuring (Transposing) SAS Data Sets
    1. Introduction
    2. Task: Converting a data set with one observation per subject into one with multiple observations per subject (using a DATA step)
    3. Task: Converting a data set with one observation per subject into one with multiple observations per subject (using PROC TRANSPOSE)
    4. Task: Converting a data set with multiple observations per subject into one with one observation per subject (using a DATA step)
    5. Task: Converting a data set with multiple observations per subject into one with one observation per subject (using PROC TRANSPOSE)
    6. Conclusion
  16. Chapter 8 - Tasks Involving Dates
    1. Introduction
    2. Task: Computing a person's age, given his or her date of birth
    3. Task: Computing a SAS date given a month, day, and year (even if the day value is missing).
    4. Conclusion.
  17. Chapter 9 - Data Cleaning Tasks
    1. Introduction
    2. Task: Looking for possible data errors using a given range
    3. Task: Demonstrating a macro to report on outliers using fixed ranges
    4. Task: Demonstrating a macro that performs automatic outlier detection
    5. How the macro works
    6. Conclusion
  18. Chapter 10 - Reading Data with User-Defined INFORMATS
    1. Introduction
    2. Task: Reading a combination of character and numeric data
    3. Conclusion
  19. Chapter 11 - Tasks Involving Multiple Observations per Subject
    1. Introduction
    2. Task: Using PROC SORT to detect duplicate BY values or duplicate observations (records)
    3. Task: Extracting the first and last observation in a BY group
    4. Task: Detecting duplicate BY values using a DATA step
    5. Task: Identifying observations with exactly 'n' observations per subject
    6. Task: Computing differences between observations (for each subject)
    7. Task: Computing the difference between the first and last observation for each subject
    8. Conclusion
  20. Chapter 12 - Miscellaneous Tasks
    1. Introduction
    2. Task: Determining the number of observations in a SAS data set (using the NOBS= SET option)
    3. Task: Determining the number of observations in a SAS data set and assigning the value to a macro variable
    4. Task: Determining the number of observations in a SAS data set (using library tables)
    5. Task: Determining the number of observations in a SAS data set (using SAS functions)
    6. Task: Counting the number of a specific response in a list of variables
    7. Task: Computing a moving average
    8. Task: Presenting a macro to compute a moving average
    9. Task: Replacing the first eight digits of a credit card number asterisks
    10. Task: Sorting within an observation (using the ORDINAL function)
    11. Task: Sorting within an observation (using CALL SORTN)
    12. Task: Computing the average of the 'n' highest scores
    13. Task: Extracting the first and last name (and possibly a middle name) from a variable containing the first and last name (and possibly a middle name) in a single variable
  21. Index
  22. Accelerate Your SAS Knowledge with SAS Books

Product information

  • Title: Cody's Collection of Popular SAS Programming Tasks and How to Tackle Them
  • Author(s): Ron Cody
  • Release date: September 2012
  • Publisher(s): SAS Institute
  • ISBN: 9781629597768