I create a hash for my ID variable with sha256 and apply the $hex64. format for readability. But when the ID is missing then it gets a hash value of 20202020... The receiver of my data will only receive the hash_ID, and I want to prevent they assume this ID was known and can be found by me,or that everyone with this hash is the same ID. Is there a way to get these missings to be displayed as missing also in the $hex64. format?
data test;
input file ID $5.;
datalines;
1 02156
2 00369
3 45896
4
5 78954
6
7 78954
;
run;
proc sql;
create table hash as
select ID,
(case when ID ne "" then sha256(cat("XXX",ID)) else "" end) as hash_ID format = $hex64.
from test;
quit;
A good case for creating your own format, slightly different from hex
data test;
input file ID $5.;
datalines;
1 02156
2 00369
3 45896
4
5 78954
6
7 78954
;
run;
proc format;
value $ myhex
' ' = ' '
other = [$hex64.]
;
run;
proc sql;
create table hash as
select ID,
(case when ID ne "" then sha256(cat("XXX",ID)) else "" end) as hash_ID format = $myhex.
from test;
quit;
Result:
ID hash_ID 02156 6098C1ED4949D1E7A4EA72C986640C40735CD5D1F201E9FC5DEE94435DE676F6 00369 C79B09E1F340DCCC54FD1816BB9CD4A21C2AD7795674E5156784368C2EFB1A40 45896 563FF6307A5DA67B9BBB3D383F6A12BCBDC54AEA03BFFB3358FDC1E6A75DDF6B 78954 F47211D85F84F5E03620727912C4382D601B064D52F3A8D2D38EDFD9B0DE5D7F 78954 F47211D85F84F5E03620727912C4382D601B064D52F3A8D2D38EDFD9B0DE5D7F
A good case for creating your own format, slightly different from hex
data test;
input file ID $5.;
datalines;
1 02156
2 00369
3 45896
4
5 78954
6
7 78954
;
run;
proc format;
value $ myhex
' ' = ' '
other = [$hex64.]
;
run;
proc sql;
create table hash as
select ID,
(case when ID ne "" then sha256(cat("XXX",ID)) else "" end) as hash_ID format = $myhex.
from test;
quit;
Result:
ID hash_ID 02156 6098C1ED4949D1E7A4EA72C986640C40735CD5D1F201E9FC5DEE94435DE676F6 00369 C79B09E1F340DCCC54FD1816BB9CD4A21C2AD7795674E5156784368C2EFB1A40 45896 563FF6307A5DA67B9BBB3D383F6A12BCBDC54AEA03BFFB3358FDC1E6A75DDF6B 78954 F47211D85F84F5E03620727912C4382D601B064D52F3A8D2D38EDFD9B0DE5D7F 78954 F47211D85F84F5E03620727912C4382D601B064D52F3A8D2D38EDFD9B0DE5D7F
Do this:
case
when ID ne ""
then put(sha256(cat("XXX",ID)),$hex64.)
else ""
end as hash_ID
or, in a data step
data hash;
set test;
length hash_id $64;
if id > "" then hash_id = put(sha256(cat("XXX",ID)),$hex64.);
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: