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);

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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