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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

6 REPLIES 6
Reeza
Super User

Isn't the hex32. the printable values one?

data set_1;

member='JOSEPH';

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

put member2=;

run;

joe29
Calcite | Level 5

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!

Reeza
Super User

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;

joe29
Calcite | Level 5

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;

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

 

Reeza
Super User

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

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

joe29
Calcite | Level 5

Thank you!! That worked!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 8495 views
  • 0 likes
  • 2 in conversation