BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

I've trouble understanding the defining keys and data in hashing. I read the document under

 

http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#n1b4cbtmb049xtn1vh9x...

 

Still I couldn't understand. May I request someone to explain about defining keys and data in hashing in simple terms?

 

Thanks in advance for any help you offer me.

2 REPLIES 2
Steelers_In_DC
Barite | Level 11

I am going through some training myself so there are most likely better sources but I will explain something as I understand it to join the conversation:

 

data want;
merge emphours (in=a)
      employees(in=b);
by empid;
if a;
run;

data empinfo;
length empid $6. empln $30. empfn $25. empmi $1. gender $1. startdate 8. emppaylevel $5.;
if _N_ = 1 then do;
    declare hash new(dataset: 'employees',ordered: 'y');
    new.definekey('empid');
    new.definedata('empln','empfn','empmi','gender','startdate','emppaylevel');
    new.definedone();
call missing(empln,empfn,empmi,gender,startdate,emppaylevel);
end;
set emphours;
rc = new.find();
drop rc;
format startdate mmddyy10.;
run;

 

The two pieces of code produce the same results, definekey is the key in the hash table that I am generating and the field that I will be joining on.  definedata() is the fields that I want to pull in.  This is a simple merge, I am pulling fields from the employee dataset, joining to the emphours dataset.  This is a very simple example for hash.

 

Hope I provided some help.

 

Mark

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2553 views
  • 2 likes
  • 3 in conversation