- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Report it to SAS support.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
reported: ticket # CS0242442.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
My SAS 9.4M5 (on Windows 7) does not show any of these unexpected effects. All results appear to be correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.