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

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 610 views
  • 0 likes
  • 1 in conversation