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

Hello,

 

Below, my data step :

 

data test;

length c2 $ 64 c1 $ 64;

format c2 $hex64. c1 $hex64.;

c1=sha256('8811421');

c2=sha256('8811531');

run;

 

I don't understand why c1 is null while c2 is ok.

C2 = 327B1D31BCEC3EAF555B0FB984ABFBC21C564E7D7B4C21D032DE47E62534BB12

 

Can you help me ?

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
Amir
PROC Star

It might be a display issue, as per:

 

https://communities.sas.com/t5/SAS-Programming/SHA256-does-not-generate-the-same-length-of-encryptio...

 

As can be seen in the response from @andreas_lds to your post, c1 starts with 00, which is also highlighted in the link above.

 

Try putting the values to the log, rather than viewing the data set and see if that helps, as per the link.

 

 

Regards,

Amir.

 

 

View solution in original post

7 REPLIES 7
andreas_lds
Jade | Level 19

There must an error in your code, please check the log. When i execute the data-step you posted (two put-statements added), i get:

c1=005CF1E3EAA9EF7AC87EDA95C3EED5752D273FA165519753A37A855D7DBE8B7E
c2=327B1D31BCEC3EAF555B0FB984ABFBC21C564E7D7B4C21D032DE47E62534BB12
Amir
PROC Star

It might be a display issue, as per:

 

https://communities.sas.com/t5/SAS-Programming/SHA256-does-not-generate-the-same-length-of-encryptio...

 

As can be seen in the response from @andreas_lds to your post, c1 starts with 00, which is also highlighted in the link above.

 

Try putting the values to the log, rather than viewing the data set and see if that helps, as per the link.

 

 

Regards,

Amir.

 

 

Charlotte37
Fluorite | Level 6








Thanks for your feedback. Indeed, with a "Put", I see my hash key
Charlotte37
Fluorite | Level 6








I use the hash key in 2 tables to compare and find differences between the tables.
How to make the join between the 2 tables on the hash key if sometimes she is empty?
Amir
PROC Star

The full hash value should always be there in the table, this is just a display issue.

 

Comparisons using program code will compare the full hash values held, not the values displayed.

 

 

Regards,

Amir.

andreas_lds
Jade | Level 19

@Charlotte37 wrote:

I use the hash key in 2 tables to compare and find differences between the tables.
How to make the join between the 2 tables on the hash key if sometimes she is empty?

 

Just to underline what @Amir already said: the value is the table, and joining/merging etc. work as intended. Can you show as the code not generating the expected result? If the lengths of the variables you use in sha256 are not the same, you will get different results, even if the shown values are the same - in sas all char-variables are padded with blanks. To avoid this, use

hash = sha256(trim(original));
Charlotte37
Fluorite | Level 6
Thanks

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 2059 views
  • 3 likes
  • 3 in conversation