BookmarkSubscribeRSS Feed
yashpande
Obsidian | Level 7
I have list of personal columns which needs to be masked/encoded/encrypted so sensitive information is not passed to all the users.

Column list is customer_name,customer_id, customer_dob

So everytime we download data from production ,all these columns would have different value which are not traceable.

Input data set looks like this
customer_name customer_id customer_dob balance

Rahul 1000 29/04/2002 10058
Ramesh 1005 12/03/1998 15008

So my output can be something like this

customer_name customer_id customer_dob balance

Yaswl 5423 17/11/1992 10058
Oweqyu 6421 12/03/1998 15008


Any suggestions is highly appreciated


4 REPLIES 4
Ksharp
Super User

Here is my code.

 


Data have;
input  MEZAHE_PART $;
cards;
MEZAHE_
9
710
1040
1323
1417
1610
1618
1922
2143
2323
2413
2511
2629
2823
3026
3218
3711
3720
3928
4213
4219
4223
4318
4811
5283
5428
6315
6320
6412
6610
6726
6727
6915
6919
7125
7222
7514
7620
7958
8119
8213
8420
9327
9721
9726
9827
;
Run;
data want;
 set have;
 length encode $ 20;
 temp=MEZAHE_PART;
 do i=1 to lengthn(temp);
   encode=cats(encode,byte(rank(char(temp,i)) + 1));
 end;
 drop temp i;
run;
data want;
 set want;
 length decode $ 20;
 do i=1 to lengthn(encode);
   decode=cats(decode,byte(rank(char(encode,i)) - 1));
 end;
 drop i;
run;
yashpande
Obsidian | Level 7

This is very much on the lines of my expected output. Now I have got more clarity and sample. So here is my control table which has list of columns which needs to be encoded 

Column  Type
person_name Char
legal_name Char
legal_name_GRIDORG Char
date_of_birth Num
prs_birtNowh_dt Num
birth Num
deceased_date Num
deceased_notification_date Num
prefix_name Char
initials Char
client_name Char
legal_name_eup Char
relation_nr

num

 

 

And here is the Sample data 

relation_nr relation_type relation_start_date relation_end_date date_of_birth established_date deceased_date deceased_notification_date person_name prefix_name initials segment_cd
918598 P 11/4/1994 . 9/7/1972 . . . Nolte   B 390
918814 P 11/4/1994 . 3/4/1924 . 6/6/2019 ######## Bruggen van der A 390
918832 P 11/4/1994 . 11/20/1926 . . . Griffioen   J 390
918857 P 11/4/1994 . 5/3/1929 . ######## ######## Kneppers   H 390
918923 P 11/4/1994 . 1/29/1932 . ######## 5/8/2018 Noort van J 390
918997 P 11/4/1994 . 7/17/1914 . 4/7/2008 ######## Heijermans   L 390
919224 P 11/4/1994 . 12/15/1947 . ######## ######## Schaap   R 390
919222 P 11/4/1994 . 3/16/1951 . . . Beleir de APM 390
919271 P 11/4/1994 . 6/28/1961 . . . Kolk van der CJ 390
919136 P 11/4/1994 . 5/30/1975 . . . Schoorl   HJ

390

 

 

So How do I generate the encoding and if required how can I decode it ? Any further help is highly appreciated

Ksharp
Super User

Since your data are all ASCII characters, I recommend to use Ron.Cody 's method I mentioned before:
https://blogs.sas.com/content/sgf/2024/01/10/using-the-bxor-function-to-encode-and-decode-text/

 

Firstly, convert all these numeric type variable into character type and using Ron's code to encrypt your data.

Here is an example how to convert:

 

 

proc contents data=sashelp.class out=out noprint varnum;
run;

proc sql noprint;
select name into :vnames separated by ' ' from out where TYPE=1;
select catt('char_',name,'=left(vvalue(',name,'));') into :convert separated by ' ' from out where TYPE=1;
quit;
data want;
 set sashelp.class;
 &convert.
 drop &vnames.;
run;

After getting WANT dataset , you could feed it into mine or Cody's macro to encrypt or decrypt string.



data encrypt;
 set want;
array x{*} $ _character_;
do j=1 to dim(x);
 do i=1 to lengthn(x{j});
   substr(x{j},i,1)=byte(rank(char(x{j},i)) + mod(i,5));
 end;
end;
 drop j i;
run;
data decrypt;
 set encrypt;
array x{*} $ _character_;
do j=1 to dim(x);
 do i=1 to lengthn(x{j});
   substr(x{j},i,1)=byte(rank(char(x{j},i)) - mod(i,5));
 end;
end;
 drop j i;
run;

And open dataset ENCRYPT and DECRYPT ,check if these are what you are looking for.

 

Ksharp_0-1718355146095.png

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 285 views
  • 0 likes
  • 2 in conversation