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

@Patrick

Thank you very much indeed for your detailed description of the logic. I am very grateful.

Patrick
Opal | Level 21

@constliv

And here the link to the documentation (ignore the Java section):

https://support.sas.com/documentation/cdl/en/lecompobjref/69740/HTML/default/viewer.htm#titlepage.ht...

 

Also: I've used in the hash declare statement the dataset:'<table name>' directive.

dcl hash h1(dataset:'a(rename=(id=id_a balance=balance_a))', multidata:'y');

Most examples in the documentation don't use this directive. What it does: It instructs SAS not only to define the hash structure (the key and data variables) but also to directly load data into the hash from the table as defined via dataset:'<table name>'.

 

Most examples won't do this but will only define the hash table structure and then use the add() method to actually load data into the hash. Don't let this confuse you. These are just different ways how you can populate a hash table and both methods have their use cases. You'll get it once you start using hashes. It takes a bit but it's very well worth learning as it opens possibilities you don't have without hashes.

 

One common use case: You have a big unsorted base table and you need to look up variables over a composite key in a small table. Using a hash table removes the need to sort the big table which can make a big difference in regards of performance. 

A standard case is having a huge fact table looking up values in multiple dimension tables over different keys. If you load the dimension tables into SAS hashes then you can implement this look-ups in a single data step without having to sort the fact table multiple times (whether sorting is done explicitely or implicitely via a SQL join).  

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
  • 16 replies
  • 2899 views
  • 3 likes
  • 3 in conversation