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.
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;
Report it to SAS support.
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;
reported: ticket # CS0242442.
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
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.
My SAS 9.4M5 (on Windows 7) does not show any of these unexpected effects. All results appear to be correct.
@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.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.