Hash Object Processing

At the beginning of the DATA step execution that follows, the hash object ContName is declared with a key component of ContinentID and data component of ContinentName. The Certadv.Country table is used to populate the hash object.
data work.countrycode;
   drop rc;
   length ContinentName $30;
   if _n_=1 then do;                                    /*1*/
      call missing (ContinentName);                     /*2*/
      declare hash ContName();                          /*3*/
      ContName.definekey('ContinentID');                /*4*/
      ContName.definedata('ContinentName');             /*5*/
      ContName.definedone();                            /*6*/
      ContName.add(key: 91, data: 'North America');     /*7*/
      ContName.add(key: 93, data: 'Europe');
      ContName.add(key: 94, data: 'Africa');
      ContName.add(key: 95, data: 'Asia');
      ContName.add(key: 96, data: 'Australia/Pacific');
   end;                                                 /*8*/
   set certadv.country                                  /*9*/
            (keep=ContinentID Country CountryName);
   rc=ContName.find();                                  /*10*/
run;                                                    /*11*/
proc print data=work.countrycode noobs;
run;
  1.    if _n_1= then do;
    When the _N_ is equal to 1, it declares and defines the hash object only one time.
    Program Data Vector
  2. call missing (ContinentName);
    CALL MISSING sets the key column, ContinentName, to missing.
  3. declare hash ContName();
    The DECLARE statement declares a hash object named ContName with no arguments.
    Program Data Vector
  4. ContName.definekey('ContinentID');
    The DEFINEKEY method specifies the ContinentID column as the key component.
    Program Data Vector
  5. ContName.definedata('ContinentName');
    The DEFINEDATA method specifies the ContinentName column as the data component.
    Program Data Vector
  6. ContName.definedone();
    The DEFINEDONE method indicates that the key and data components are complete.
    Program Data Vector
  7. ContName.add(key: 91, data: 'North America');
    ContName.add(key: 93, data: 'Europe');
    ContName.add(key: 94, data: 'Africa');
    ContName.add(key: 95, data: 'Asia');
    ContName.add(key: 96, data: 'Australia/Pacific');
    The ADD method adds the specified data that is associated with the given key to the hash object. This method returns a zero if adding is not successful.
    Program Data Vector
  8. end;
    The END statement ends the group processing.
  9. set certadv.country (keep=ContinentID Country CountryName);
    The SET statement reads observations from Certadv.Country data set and the KEEP= data set option keeps only the specified variables.
    Program Data Vector
  10. rc=ContName.find();
    The FIND method searches the ContName hash object for the current key values. The function returns a 0 if the key is found. The key value is not returned to the PDV.
    Program Data Vector
  11. The RUN statement has an implicit OUTPUT statement and an implicit RETURN statement.
The DATA statement initializes the PDV again after the RUN statement. On the second iteration of the DATA step the IF statement does not execute again because _N_ is not equal to 1. This continues until the end-of-file marker is reached.
Output 12.1 PROC PRINT of Work.Countrycode
PROC PRINT of Work.Countrycode
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
18.190.25.193