DATA Step, Macro, Functions and more

Hash help

New Contributor
Posts: 2

Hash help

I am really new to using hash objects. I can do the basics, but I was wondering if someone can lend me a little help. The short version is that I want to compare the key (ID) with two different variables in the hash object (ID and parentID). If ID matches ID in the hash object, I want the program to pull some data into the main data set. I know how to do this portion. However, I also want to compare ID to the variable parentID in the hash object, and if they match, then I want to put a "yes" in a different variable (parent) in the main data set. Is it possible to do this, to compare the key to two different variables in the hash? The code I have so far is below, and it does the first portion of what I want of pulling in information if the key matches. 

data TCE.infoflag;

length ParentID $13;

length ParentName $80;

length ParentNPLStatus $30;

set TCE.infoflag;

if _n_= 1 then do;

     declare hash hh(dataset: 'NPL.parent');


     hh.definedata('ParentID', 'ParentName', 'ParentNPLStatus');



     if hh.find() ge 0;


Super User
Posts: 10,787

Hash help

Welcome to Hash World!.

I bet you will like it more and more.

About your question, I think answer is yes.

You need build another Hash Table to hold parentID as a key, then use check() method to see whether they are matched.

If matched then parent='yes';

The best way to get answer is to post some sample data and output you need.


New Contributor
Posts: 2

Hash help

Thanks Ksharp. That is what I ended up doing. I was trying to figure out if it could all be done in one data step. I am still trying to understand hash coding.

Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation