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;
-
When the _N_ is equal
to 1, it declares and defines the hash object only one time.
-
call missing (ContinentName);
CALL MISSING sets the
key column, ContinentName, to missing.
-
The DECLARE statement
declares a hash object named ContName with no arguments.
-
ContName.definekey('ContinentID');
The DEFINEKEY method
specifies the ContinentID column as the key component.
-
ContName.definedata('ContinentName');
The DEFINEDATA method
specifies the ContinentName column as the data component.
-
The DEFINEDONE method
indicates that the key and data components are complete.
-
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.
-
The END statement ends
the group processing.
-
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.
-
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.
-
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