Hi,
I am learning hash objects ,when I was working on the below scenario,it is giving as specified below.please clarify.
I have two data sets ,I am assuming that one is bigger one and one is smaller one.
the smaller data(data1) set consists of following data.
connection_id credit_teamid
the bigger one(master) data set consists of following data.
Connection_id credit_teamid unit_desc group_code
DATA Hash_sample(drop=search);
length connection_id 10;
length credit_team_id unit_desc group_code $20;
if _n_=1 then do;
declare hash first_HT(dataset:"master");
first_ht.definekey("connection_id","credit_team_id");
first_ht.definedata("unit_desc","group_code");
first_ht.definedone();
end;
set data1;
search=first_ht.find();
if search=0 then output;
run;
Here I'm getting the output like this
Even though master data set consists of same connection id and credit team id's more than once,small data set is not merging with all the connection and credit team id's in the master data set.
It is only merging with first occurance(first.) of the connection id and credit team id's of the master data set.
Please clarify.
Try using the Multidata: 'Y' option in the Declare Hash statement: declare hash first_HT(dataset:"master", Multidata: 'Y');
Regards,
Hi CTorres,
I tried with the multidata,It is giving the error message :unknown argument Multidata.
be sure to use the colon(:) in the Multidata option: Multidata:
Maybe double quotes?
Look at the documentation: SAS(R) 9.3 Component Objects: Reference
Regards
For loading "master" into a hash you would need "multidata" with the keys you've chosen. You then would also need to iterate through the groups with the same key as shown here:
SAS(R) 9.3 Component Objects: Reference
But actually for what I believe you're trying to achieve it would be much better to load the small data set into a hash. As the key variables exist in both "master" and "data1" you don't need to define the variables for the hash if "setting" master before the hash definition.
Code as below should do (not tested):
DATA Hash_sample (drop=_:);
set master;
if _n_=1 then
do;
declare hash first_HT(dataset:"data1");
_rc=first_ht.definekey("connection_id","credit_team_id");
_rc=first_ht.definedone();
end;
if first_ht.find()=0 then output;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.