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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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