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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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 

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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 
Kurt_Bremser
Super User

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2 replies
  • 1205 views
  • 1 like
  • 3 in conversation