Scenario 6

Directions

This scenario uses the Excel file heart.xlsx. Write a SAS program to do the following and store the results in the data set Work.Heart.
  • Import the Excel file heart.xlsx.
  • Drop the AgeAtDeath and DeathCause variables from the Work.Heart data set.
  • Include only the observations where Status=Alive in the Work.Heart data set.
  • If the AgeCHDdiag variable has a missing value (.), then do not include the value in Work.Heart.
  • Create a new variable Smoking_Status, set its length to 17 characters, and use the following criteria:
    • If the value of Smoking is between 0 and less than 6, then Smoking_Status is "None (0–5)".
    • If the value of Smoking is between 6 and 15 inclusively, then Smoking_Status is "Moderate (6–15)".
    • If the value of Smoking is between 16 and 25 inclusively, then Smoking_Status is "Heavy (16–25)".
    • If the value of Smoking is greater than 25, then Smoking_Status is "Very Heavy (>25)".
  • If there are any other values for the variable Smoking, set Smoking_Status to "Error".
  • Create a two-way frequency table using variables AgeCHDdiag and Smoking_Status and suppress column percentage, row percentage, and cell percentage.

Test Your Code

  1. What is the total number of Heavy Smokers (16–25)?
  2. What is the frequency value of Very Heavy (>25) smokers for AgeCHDDiag 48?
  3. What is the frequency value of Smoking_Status = "Error"?

Objectives Accomplished

  • Access SAS data sets with the SET statement.
  • Use a DATA step to create a SAS data set from an existing SAS data set.
  • Use IF-THEN/ELSE statements to process data conditionally.
  • Use assignment statement to create new variables and assign a value in the DATA step.
  • Define the length of a variable using the LENGTH statement.
  • Generate summary reports and frequency tables using Base SAS procedures.
Last updated: February 14, 2019
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset