BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
EinarRoed
Pyrite | Level 9

This code creates a concatenated string based on primary key values in the source table. This in turn is used to create a hex value.

 

%let source_keys = ORGNR PRODUCT_ID OBJECT_ID;
data want;
	set have;
	source_keys_concat = catx('_',of &source_keys.);
	attrib target_hex length=$16 format=$hex32.;
	target_hex = md5(source_keys_concat);
run;

The MD5 function mostly seems to work as intended. But it also generates some bizarre outputs (including NULL values):

Skjermbilde 2022-08-10 123151.png

The input values (source_keys_concat) are consistent, so why doesn't the MD5 function generate consistent output values?

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

If you want to store $hex32. you need a variable with length 32:

 

data want;
  set have;
  source_keys_concat = catx('_',of &source_keys.);
  attrib target_hex length=$32;
  target_hex = put(md5(source_keys_concat), $hex32.);
run;

View solution in original post

5 REPLIES 5
andreas_lds
Jade | Level 19

Please post the result dataset as data step, so we can use your data for analysis. The number of obs shown in the screenshot is sufficient. We don't anything more, but those two variables.

EinarRoed
Pyrite | Level 9

Thanks, here you go:

 

cards;
00912622266_P05_174604509 2202F7E7AC80E7C869D1031F6CC54D4A
00912622266_P05_174604517
00912622266_P15_174604517 651040CBB8C3D7B672F7
00912849376_P05_156838543 C31041BBB805D00BE4CFC84AD15BBCBE
00912849376_P15_156838543 319B61CA4F9C32092DAB19794942FF8B
00912849376_P05_7604653 AC8FEB0E918B10DB4955DF0981EF7F21
00912991695_P15_140399817 8AA120EC8A8EE5381D90F1C6F2CA80F2
00912993159_P05_152364687 EDA5FA
00913038185_P05_185043568 B182F2A5F518AE164D41B2E4C6371072
00913084896_P15_140458392 97A88777FA4C6AFAD0BCF80ACCE9BC73
00913442490_P05_7252749 CAF80EDD43A144BDF9A2CFF8ECC9BCC4
00913442490_P15_7252749 913B4003380DE9941CD8D453273AE47B
00913442490_P05_7263678 CF7C7166B33F57822A8A2A8297C2CE36
00913538129_P15_179728532 12C2CF920DCC9CAD2978B0D9315C40F5
00913555708_P05_153271178 CEF9320ACD393AB8EAF6BFF9C2EC343F
00913821157_P05_155542225 624FBAE622D716CD61109FD2754DC474
00913821157_P15_155542225 DFC12BC04D655A25B495361B01BC845D
00913821157_P05_300644375 A223FE96
00914315220_P05_7776640 B8961D53F5068F6BCA76B2945560506B
;
andreas_lds
Jade | Level 19

If you want to store $hex32. you need a variable with length 32:

 

data want;
  set have;
  source_keys_concat = catx('_',of &source_keys.);
  attrib target_hex length=$32;
  target_hex = put(md5(source_keys_concat), $hex32.);
run;
EinarRoed
Pyrite | Level 9
Aha you're of course right. Runs well now, thanks. 🙂
FreelanceReinh
Jade | Level 19

Hello @EinarRoed,

 

I think it's rather a problem of your user interface (SAS Enterprise Guide?) displaying strings containing the '00'x character (even though this character should display as "00" in the $HEX32. format). I can replicate the issue with my SAS EG 7.15. In a Display Manager SAS 9.4M5 session (under Windows), however, the problem does not occur. So I'd expect that the original target_hex variable of length 16 would serve its purpose as a key variable very well in spite of the display issue (as always, only the internal values count) and that you would not need to store the $HEX32.-formatted value instead, duplicating the required length to 32 bytes.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 601 views
  • 3 likes
  • 3 in conversation