BookmarkSubscribeRSS Feed
david27
Quartz | Level 8

Team,

 

I am following this SAS Paper-- http://support.sas.com/resources/papers/proceedings17/0949-2017.pdf

 

I am trying to encrypt a variable using tranwrd function. Below is the code:

 

The problem is:
It gives me same value for Jane and Janet. How can I rectify this?

 

%let multi =3 ;
%let k =  359;
%let gap =  9;

data encrypt ;
set sashelp.class;
Encrypt_names = name;
i = input(&k., best.);
do old=     
           'a','b','c','d','e','f','g','h','i','j',
                'k','l','m','n','o','p','q','r','s','t',
                'u','v','w','x','y','z',
           'A','B','C','D','E','F','G','H','I','J',
                'K','L','M','N','O','P','Q','R','S','T',
                'U','V','W','X','Y','Z'
           ;
     new=put(i,&multi..);
     encrypt_names= tranwrd(encrypt_names,old,new);
     i+input(&gap.,best.);
end;
drop i new old;
run;

tranwrd.PNG

1 REPLY 1
david27
Quartz | Level 8

So I resolved soon after I posted.

I have to increase length of the variable.

Added this piece---length encrypt_names $512.;

 

Any better ways to encrypt values are more than welcome. Thank You

 

The new code is:

 

%let multi =3 ;
%let k =  359;
%let gap =  9;

data encrypt ;
set sashelp.class;
length encrypt_names $512.;
Encrypt_names = name;
i = input(&k., best.);
do old=     
           'a','b','c','d','e','f','g','h','i','j',
                'k','l','m','n','o','p','q','r','s','t',
                'u','v','w','x','y','z',
           'A','B','C','D','E','F','G','H','I','J',
                'K','L','M','N','O','P','Q','R','S','T',
                'U','V','W','X','Y','Z'
           ;
     new=put(i,&multi..);
     encrypt_names= tranwrd(encrypt_names,old,new);
     i+input(&gap.,best.);
end;
drop i new old;
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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 648 views
  • 0 likes
  • 1 in conversation