Hi All,
BASUG is hosting a free webinar in August on hashing. But rather than simply post the description, I took a shot at a little example of using a hash table to decipher a message. If you run the below code and check the log, hopefully you'll see readable text with registration info. Hopefully. (If it doesn't work, please let me know : )
Trust me, if you're interested in learning more about hashing, you don't want to miss this!
*Build the lookup table to decipher the message ;
data chars (keep=char rand);
call streaminit(12345);
length chars $95;
chars = collate(32,127);
do i=1 to length(chars) ;
char=substrn(chars,i,1) ;
rand=rand("Uniform") ;
output ;
end ;
run;
proc sort data=chars ;
by rand ;
run ;
data cipher ;
set chars (keep=char);
code=put(_n_,z2.) ;
run ;
*Read the message,
read lookup table into a hash table,
and use to decipher the message
;
data _null_ ;
if 0 then set cipher ;
if _n_=1 then do ;
declare hash h(dataset:"cipher") ;
h.definekey("code") ;
h.definedata("char") ;
h.defineDone() ;
end ;
infile cards missover;
do i=1 to 100 ;
input code $2. @;
if not missing(code) then do ;
h.find(key:code) ;
put char +(-1) @ ;
end ;
end ;
put ;
cards ;
374429261830144549713570459271936149082445926154544569710870882471452944294524091627451470082445128814144559083471242313
128814144592615454454824711471497045474449454449612208707138451888613871457009452944294573081452614905464575240922450409882445756124147045730814524570094573081452450969457308145271144713
427138497114380823194544880588147045100645631046070785634677074536264390856583
4352714592719361490824456114457512787819459388704524710561147024087061094945611445247184886124713813
7588545445084949098849167122714970453692617052452471056114702408706109494554614927834645527070484628289292921393081488051309240528713471497014289310071007075013483869
;
*check your log to read the message! ;
--Q.
Thanks @PeterClemmensen . Glad it worked! I've been enjoying the hashing posts on your blog, e.g. https://sasnrd.com/sas-hash-object-content-log-puthash/ .
Now that's a novel means of communication.
I signed up. Hopefully no one will assign me a conflict at work.
Jim
P.S. I suppose a more proper response would be:
91710824452588714970614919 435208492745230988453471242345228816524569092445230988244527614938456149346170087061094913 41450524087071698854542345081616714870194508493845414508224554090927614905456909249208243845700945617013 29614916712471542345230988241419 336122
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.