DATA Step, Macro, Functions and more

SAS beginner needs help with basic MD5 function

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

SAS beginner needs help with basic MD5 function

When using the MD5 function, is there a way to keep the 32 bit encrypted value printable?

data set_1;

member='JOSEPH';

member2=md5(member);

put member2= / member2 = hex32.;

run;

The above outputs a variable called member2 with non printable values.  What I need is the 32 bit md5 printable value.  Could someone please help?

Thanks


Accepted Solutions
Solution
‎05-21-2013 04:57 PM
Super User
Posts: 17,829

Re: SAS beginner needs help with basic MD5 function

Isn't the hex32. the printable values one?

data set_1;

member='JOSEPH';

member2=put(md5(member), hex32.);

put member2=;

run;

View solution in original post


All Replies
Solution
‎05-21-2013 04:57 PM
Super User
Posts: 17,829

Re: SAS beginner needs help with basic MD5 function

Isn't the hex32. the printable values one?

data set_1;

member='JOSEPH';

member2=put(md5(member), hex32.);

put member2=;

run;

Occasional Contributor
Posts: 5

Re: SAS beginner needs help with basic MD5 function

Hi Reeza, Could you help with this question?

I have a dataset called "list1".  It has one variable called "name" with one record. The value in the only record is "joseph".  Could you tell me the values for hash1 and hash2 in the below code are not the same?  The value for hash 2 is the correct one.

I'm trying to figure out how to get correct md5 hash values for a list of 5 million names in a dataset.

data list2;

set list1;

hash1=put(md5(name),hex32.);

hash2=put(md5('joseph'),hex32.);

run;

Thanks for any help!

Super User
Posts: 17,829

Re: SAS beginner needs help with basic MD5 function

md5 is case sensitive.  See the code below.

data test;

input name $;

cards;

Joseph

JoSeph

joseph

JOSEPH

;

run;

data want;

set test;

hash=put(md5(name), hex32.);

run;

Occasional Contributor
Posts: 5

Re: SAS beginner needs help with basic MD5 function

[ Edited ]

Thanks for the reply Reeza.  Sorry to be a pain but I still can't figure it out. Here's exactly what I'm working on.

 

I have sample list of 5 email address that I need MD5 hash values for.

 

This is the sample code I used:

 

/********************************/
data email_adds;
infile 'C:\Documents and Settings\Joe\Desktop\email_adds.txt'
delimiter='09'x MISSOVER DSD lrecl=32767 firstobs=2 ;
informat EMAIL $29. ;
format EMAIL $29. ;
input EMAIL $;
run;

 

data email_adds2;
set email_adds;
hash=put(md5(email), hex32.);
run;

 

/********************************/

 

Here is the output with INCORRECT hash values:

 

 

The hash value for  should be CC09B70444EA2093D940D2E86B637416. I confirmed this using an online hash generator (http://www.md5hashgenerator.com/index.php)

 

 

 

I also tried this to confirm.  Hash2 is correct:

 

/********************************/

data test;

email='';

hash=put(md5(email), hex32.);

hash2=put(md5(''), hex32.);

run;

/********************************/

 

Super User
Posts: 17,829

Re: SAS beginner needs help with basic MD5 function

You have trailing in spaces in your data. Add a trim function in to remove the trailing spaces.

hash=put(md5(trim(email)), hex32.);

Occasional Contributor
Posts: 5

Re: SAS beginner needs help with basic MD5 function

Thank you!! That worked!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 3206 views
  • 0 likes
  • 2 in conversation