BookmarkSubscribeRSS Feed
Haikuo
Onyx | Level 15

"The purpose for it in your example is to only create and load the hash table once, at the start of the first loop through the step. It only needs to be done once."

Agreed.

"If you removed this check the hash table would be created and loaded for every record the step is processing!"

Hmmmm, not always. It depends heavily on your data step construct. There are constructs within which loops just once but output multiple records(eg. output()), or loops a lot less than the records it outputs or processes, eg. wrap up 'set' statement with DOW.

So to use _n_=1 loop is more of a better practice and saft guard issue.

Regards,

Haikuo

SASKiwi
PROC Star

Cheers Haikuo. My comments were based just on the code as it stands. Of course if you change it with your own looping code then you could avoid loading the hash table for every record by another method. Just trying to keep it simple!

Haikuo
Onyx | Level 15

Hi SASkiwi,

There is NOT a second that I have questioned your or others' understanding of Hash. However, Given that OP is obviously new to Hash, I choose this  complex way to unfold more aspects in front him/her. It seems more purplex up front, but hopefully will help him with the big picture further down the road.

Regards,

Haikuo

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 40181 views
  • 11 likes
  • 8 in conversation