I'm working with Hash Tables and I'm doing multiple lookups...I'm trying to understand this code below. What is the use of Do loop increment by 0?
I thought IORC is allocated an automatic code? If so, then why say IORC=find()? Any help will be appreciated.
set Base_2 ;
do _iorc_ = b.find() by 0 while (_iorc_ = 0) ;
output ;
_iorc_ = b.find_next() ;
end ;
Looks like somebody's following PD's style of programming or his book alongside me :). AFIK, The _iorc_ variable is freely available automatic variable unless referencing an index and is automatically dropped. Here the usage is pretty much for that very purpose. The initial index value would be 0 if true and the loop will only execute if the same is 0.
Then, the need is to find and retrieve the data portion to the PDV from the hash object within the key item operation, therefore as you loop through the multiple items for the same key, you can't have the _iorc_ variable incrementing by any number until a full pass of a key multiple data item is complete.
Soon as the pointer moves past the key item, it sets return code _iorc_ to a non zero value and the loop stops. You can also use
return code rc or any other variable as return code like
do rc= b.find() by 0 while (rc= 0) ;
output ;
rc= b.find_next() ;
end ;
however you may have to drop the variable though from the output dataset. Wish I could use the same words as PD does but that's copyrighted material.
HTH
What is the use of increment by 0?
it doesn't increment, the by 0 makes sure the loop operation continues/works
do rc= b.find() by 0 while (rc= 0) ;
output ;
rc= b.find_next() ;
end ;
is exactly the equivalent of
rc=b.find();
do while (rc= 0) ;
output ;
rc= b.find_next() ;
end ;
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.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.