BookmarkSubscribeRSS Feed
LindaG
Calcite | Level 5

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.definekey('ID');

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

     hh.definedone();

end;

     if hh.find() ge 0;

run;

2 REPLIES 2
Ksharp
Super User

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.

Ksharp

LindaG
Calcite | Level 5

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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 810 views
  • 3 likes
  • 2 in conversation