Scenario 3

Code Solution

Note: On the live exam, you will be evaluated both on the results of your code and the code itself. Your code should be similar to the following example code, but does not need to match exactly:
data work.success work.fail;                          /*1*/
   drop rc;
   length CtName $30;                                  /*2*/
   if _N_=1 then do;                                   /*3*/
      call missing (CtName);
      declare hash C(dataset:'certadv.continent');    /*4*/
         c.definekey('ID');                           /*5*/
         c.definedata('CtName');                      /*6*/
         c.definedone();                              /*7*/
      end;
   set certadv.airports;                              /*8*/
   rc=c.find();                                       /*9*/
   if rc=0 then output work.success;                  /*10*/
      else output work.fail;
run;
proc print data=work.success;                         /*11*
run;
proc print data=work.fail;
run;
1 The DATA step creates two temporary SAS data sets named Work.Success and Work.Fail by reading in Certadv.Airports.
2 The LENGTH statement assigns the length of 30 to the character variable CtName.
3 The IF-THEN/DO statement loads the hash object named C for the first iteration of the DATA step only. The CALL MISSING routine assigns missing values to the CtName character variable to eliminate the uninitialized variable note in the SAS log.
4 The DECLARE statement declares the hash object named C and loads the hash object with observations and variables from the data set Certadv.Continent.
5 The DEFINEKEY method defines the variable ID as the key component.
6 The DEFINEDATA method defines CtName as the data component.
7 The DEFINEDONE method completes the definition of the hash object.
8 The SET statement reads the data from the Certadv.Airports data set.
9 The FIND method retrieves the value of CtName from the hash object if the value of ID from Certadv.Airports is in the hash object C. The RC value is equal to 0 if a match is found. If a match is not found, the RC value is a nonzero value.
10 The IF-THEN/ELSE statement subsets the data to two separate data sets. If the value for RC is 0, then output to Work.Success. If the value for RC is a nonzero number, then write output to Work.Fail.
11 The PROC PRINT step displays the observations in the Work.Success and Work.Fail data sets with the value of RC.
Output 17.3 PROC PRINT Result of Work.Success (partial output)
Partial Output: PROC PRINT Result of Work.Success
Output 17.4 PROC PRINT Result of Work.Fail
PROC PRINT Result of Work.Fail

Test Your Code Solution

  1. Correct Answer: 46
  2. Correct Answer: 3
Last updated: October 16, 2019
..................Content has been hidden....................

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