Scenario 6

Code Solution

The solution listed below is one example of a program that could be used to accomplish each task within the scenario. Your code can be different, as long as it results in the same answers.
libname certdata XLSX 'C:Userscertdataheart.xlsx';                 /*#1*/
data work.heart;                                                      /*#2*/
   set certdata.heart(drop=AgeAtDeath DeathCause);                    /*#3*/
   where Status='Alive';                                              /*#4*/
   if AgeCHDdiag=. then delete;                                       /*#5*/
   length Smoking_Status $17;                                         /*#6*/
   if 0<=Smoking<6 then Smoking_Status='Non-Smoker (0-5)';            /*#7*/
   else if 6<=Smoking<=15 then Smoking_Status='Moderate (6-15)';
   else if 16<=Smoking<=25 then Smoking_Status='Heavy (16-25)';
   else if Smoking>25 then Smoking_Status='Very Heavy (> 25)';
   else Smoking_Status='Error';                                       /*#8*/
run;
proc freq data=work.heart;                                            /*#9*/
   tables AgeCHDdiag*Smoking_Status/norow nocol nopercent;            /*#10*/
run;
1 The SAS/ACCESS LIBNAME statement creates the libref certdata, which points to the Excel workbook heart.xlsx.
2 The DATA step creates a new temporary data set named Work.Heart.
3 The SET statement indicates which worksheet in the Excel file to read. The SET statement specifies the libref (the reference to the Excel file) and the worksheet name as the input data. The DROP= data set option excludes the variables AgeAtDeath and DeathCause from being written to the data set. The DROP statement could also have been used.
4 The WHERE statement selects the observations where the value of the Status variable is Alive.
5 The IF statement causes the DATA step to continue processing only those observations that meet the condition of the expression specified in the IF statement. In the example, if the value of AgeCHDdiag is missing, then those observations are removed from the data set.
6 The LENGTH statement specifies that the length of Smoking_Status is set to 17 and is a character variable. This is used to avoid truncating values.
7 The IF/ELSE IF statements create values for the Smoking_Status variable by subsetting smoking values.
8 The ELSE statement gives an alternative action if all the other IF-THEN/ELSE statements are not executed.
9 The FREQ procedure creates a two-way frequency for Work.Heart.
10 The TABLES statement requests a two-way frequency table for the variables AgeCHDdiag and Smoking_Status. The options norow, nocol, and nopercent suppress row percentages, column percentages, and cell percentages.
Output A2.8 Partial Results: PROC FREQ Results
Partial Results: PROC FREQ Results

Test Your Code Solution

  1. Correct Answer: 102
  2. Correct Answer: 2
  3. Correct Answer: 3
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