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