Hash Lookup- On obs NOTin lookup table

Accepted Solution Solved
Reply
Contributor
Posts: 38
Accepted Solution

Hash Lookup- On obs NOTin lookup table

Hello,

 

Please execute the code below.

 

Customer is my LookUP Table.

RAW is the file that I get and I have to split it based on the parent group-pa_grp.

Observations that are in RAW and also in Customer gets split properly.

But observations that are in RAW but NOT in Customer go into the "unknown" table as the code says. But it populates the variable pa_grp. 

 

Why does it do that?

I am not sure WHY it is getting populated.

 

Again--

The observations found in the table- Unknown are NOT in the lookup table named - customer.

 

 

Thank You for your help.

 

The code is---

data customer;
input _ID :$8. pa_grp $8.;
datalines;
1 ABC
1 HIJ
2 ABC
3 ABC
25 HIJ
5 HIJ
6 HIJ
7 XYZ
8 XYZ
9 XYZ
;run;
data RAW;
input _ID $8. ;
datalines;
1
2
3
5
8
9
88
66
24
26
;run;

data ABC HIJ XYZ unknown;
format pa_grp $8.;
if _n_ = 1 then do;
if 0 then set work.customer;
declare hash lkup (dataset: 'work.customer', multidata:'y');
lkup.DefineKey ('_ID');
lkup.DefineData ('pa_grp');
lkup.DefineDone ();
end;
set RAW;
rc = lkup.find();
if rc=0 then do;
if index(pa_grp,'ABC') then output ABC;
if index(pa_grp,'HIJ') then output HIJ;
if (index(pa_grp,'ABC')=0 and index(pa_grp,'HIJ')=0) or index(pa_grp,'XYZ') then output XYZ;
end;
ELSE do;
output unknown;
end;

lkup.has_next(result:r);

do while (r ne 0);
r = lkup.find_next();
if r=0 then do;
if index(pa_grp,'ABC') then output ABC;
if index(pa_grp,'HIJ') then output HIJ;
if (index(pa_grp,'ABC')=0 and index(pa_grp,'HIJ')=0) or index(pa_grp,'XYZ') then output XYZ;
end;
ELSE do;
output unknown;
end;

lkup.has_next(result:r);
end;
RUN;


Accepted Solutions
Solution
‎03-10-2016 03:38 PM
Contributor
Posts: 38

Re: Hash Lookup- On obs NOTin lookup table

Insert this in the line before you set the RAW table:

 

call missing (of _all_);

Using the multidata option retains the values that were defined as data in the hash object. You must make sure that the next data step iteration clears them out.

View solution in original post


All Replies
Solution
‎03-10-2016 03:38 PM
Contributor
Posts: 38

Re: Hash Lookup- On obs NOTin lookup table

Insert this in the line before you set the RAW table:

 

call missing (of _all_);

Using the multidata option retains the values that were defined as data in the hash object. You must make sure that the next data step iteration clears them out.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 277 views
  • 0 likes
  • 2 in conversation