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

Hey Guys, I am trying to encrypt the ssn and fname variables using the below code; The ssn seems to be working, but not the fname. Any suggestions or tweaks for making this work?

%let ssn_enc=Y*Z$%^WX&(;
%let ssn_pass=1029384756;

%let name_enc=!@#$%^&*()*^%$#@!%^&()^%$#;
%let name_pass=ABCDEFGHIJKLMNOPQRSTUVWXYZ;

data new;
    input fname $8. ssn $9;
    cards;
John 123456789
daniel 851295790
steve 473967594
becky 203954769
;
run;

data new1;
    set new;
    length encrypt_ssn $9. encrypt_fname $10.; /* Length of encrypted variables */

    /* Encrypt SSN */
    encrypt_ssn = '';
    do i=1 to 9;
        encrypt_ssn = encrypt_ssn || translate(strip(substr(ssn,i,1)), symget('ssn_pass'), symget('ssn_enc'));
    end;

    /* Encrypt fname */
    encrypt_fname = '';
    do i=1 to 8; 
        encrypt_fname = encrypt_fname || translate(strip(substr(fname,i,1)), symget('name_pass'), symget('name_enc'));
    end;

run;
1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

If you run PROC CONTENTS and PROC PRINT on work.new, you'll see that your first step has not created the dataset you are hoping for.  Perhaps try:

 

data new;
    input fname : $8.  ssn : $9.;
    cards;
John 123456789
daniel 851295790
steve 473967594
becky 203954769
;
run;

Then you can move on to debugging the second step.  You don't need to loop over each character.  You can just call TRANSLATE once, like:

 

data want ;
  set sashelp.class ;
  name2=translate(upcase(name),"!@#$%^&*()*^%$#@!%^&()^%$#","ABCDEFGHIJKLMNOPQRSTUVWXYZ") ;
  put name= name2= ;
run ;
The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

View solution in original post

1 REPLY 1
Quentin
Super User

If you run PROC CONTENTS and PROC PRINT on work.new, you'll see that your first step has not created the dataset you are hoping for.  Perhaps try:

 

data new;
    input fname : $8.  ssn : $9.;
    cards;
John 123456789
daniel 851295790
steve 473967594
becky 203954769
;
run;

Then you can move on to debugging the second step.  You don't need to loop over each character.  You can just call TRANSLATE once, like:

 

data want ;
  set sashelp.class ;
  name2=translate(upcase(name),"!@#$%^&*()*^%$#@!%^&()^%$#","ABCDEFGHIJKLMNOPQRSTUVWXYZ") ;
  put name= name2= ;
run ;
The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 265 views
  • 3 likes
  • 2 in conversation