BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
valleet
Calcite | Level 5

Hi all,

 

I am trying to use a hashtable  to output the data from a loop up data set in a given set when the find() method finds a match, and in

another set otherwise.

 

The problem is that when there is no match, the output I get contains the data in the hashtable corresponding to the previous

observations for which there was a match. Hence the find() method. 

 

Here is the code:

 

data matchAdmin nonmatchAdmin ;
       if 0 then set master_Eir nobs=Nb;
      if Nb^=0 then
            do;
                declare Hash masterHash (dataset:'master_Eir');
                masterHash.DefineKey ('master_eircode_checked');
                masterHash.DefineData(ALL:'YES');
                masterHash.DefineDone();
               do k=1 to n;
                    set admin_Eir point=k nobs=n;
                    rc=masterHash.find(key:admin_eircode_checked);
                    if rc=0 then do;
                         matchFound=1;
                         output matchAdmin;
                     end;
                    else do;
                       matchFound=0;
                      output nonmatchAdmin;
                   end;
        end;
end;
run;

 

Thanks for your help,

 

Thierry

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Yes, there is nothing in your code that would re-set those variables if the FIND fails.  There are a couple of ways to go about this. 

 

(1) Before outputting to NONMATCHADMIN, hard-code statements that set these variables to missing. 

 

(2) Drop the variables from NONMATCHADMIN that should be missing:

 

data MatchAdmin nonMatchAdmin (drop=list of some variables here);

View solution in original post

2 REPLIES 2
ballardw
Super User

Example data is helpful if you want code tested/debugged.

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... has instructions on how to create datastep code from an existing data set that you can paste into a text box here and let us generate data for testing.

Astounding
PROC Star

Yes, there is nothing in your code that would re-set those variables if the FIND fails.  There are a couple of ways to go about this. 

 

(1) Before outputting to NONMATCHADMIN, hard-code statements that set these variables to missing. 

 

(2) Drop the variables from NONMATCHADMIN that should be missing:

 

data MatchAdmin nonMatchAdmin (drop=list of some variables here);

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 921 views
  • 0 likes
  • 3 in conversation