SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
gdb02
Fluorite | Level 6

When I use the SHA256HEX function and the variable length is less than 256, it appears to just spill over into other fields in the data set.   In the code below, I would expect the 'y' variable to be identical, but it is not.  Is this expected behavior, or a bug?

data test;
x="I want to hide this";
y="I want to keep this";
x=SHA256HEX(strip(x));
run;
proc print data=test;
run;

data test;
format x y $256.;
x="I want to hide this";
y="I want to keep this";
x=SHA256HEX(strip(x));
run;
proc print data=test;
run;

  I'm using SAS 9.4 TS1M8 under 64 bit windows 10. 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

I agree you should report it to Tech Support. If you add a LENGTH statement for the variables (best practice), then I think it works as expected. Also, if you remove the STRIP function (or assign that on a different line) it seems to work. But it's unexpected behavior.

data test;
length x $ 256 y $ 256;
x="I want to hide this";
y="I want to keep this";
x=SHA256HEX(strip(x));
run;

 

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

Report it to SAS support.

ChrisHemedinger
Community Manager

I agree you should report it to Tech Support. If you add a LENGTH statement for the variables (best practice), then I think it works as expected. Also, if you remove the STRIP function (or assign that on a different line) it seems to work. But it's unexpected behavior.

data test;
length x $ 256 y $ 256;
x="I want to hide this";
y="I want to keep this";
x=SHA256HEX(strip(x));
run;

 

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
gdb02
Fluorite | Level 6

reported: ticket # CS0242442.

Tom
Super User Tom
Super User

Just the LENGTH statement does not help.  

33   data test;
34   length x1-x5 $16 ;
35   x1="I want to hide this";
36   x2="I want to keep this";
37   x1=SHA256HEX(strip(x1));
38   run;

NOTE: Variable x3 is uninitialized.
NOTE: Variable x4 is uninitialized.
NOTE: Variable x5 is uninitialized.
NOTE: The data set WORK.TEST has 1 observations and 5 variables.

Result

Tom_0-1745436444751.png

 

You need to actually make the variable the RIGHT length, which $64, not $256.  The 256 is the number of BITs, not BYTES in the SHA code.

 

FreelanceReinh
Jade | Level 19

My SAS 9.4M5 (on Windows 7) does not show any of these unexpected effects. All results appear to be correct.

Tom
Super User Tom
Super User

@FreelanceReinh wrote:

My SAS 9.4M5 (on Windows 7) does not show any of these unexpected effects. All results appear to be correct.


Same on Unix.  It works correctly with SAS 9.4 M5 but not with SAS 9.4 M7.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 440 views
  • 7 likes
  • 4 in conversation