BookmarkSubscribeRSS Feed
bayar
Calcite | Level 5

Hi there, 

I am trying to replace characters and digits of some variables in text file for masking purposes. The input is txt file and output is txt file. 

I want ID varaibles to replaced with 9999 and FirstName and LastName variables replaced with * leaving the first letter of the name as is in the source text file. I am using SAS EG 7.15 HF8. 

 

For example: MemberID: 123456 to 999999 

                      FirstName: John to J***

                      LastName:  Doe to D**

 

Please help,

 

Thank you

2 REPLIES 2
r_behata
Barite | Level 11
Data have;
MemberID="123456";
FirstName="John";
LastName="Doe";output;
run;

Data want;
length MemberID FirstName LastName $10.;
set have;
MemberID="999999";
substr(firstname,2)="***";
substr(LastName,2)="***";
run;
ballardw
Super User

Do you have your data in SAS yet? If not the first step is to read the file. Possibly use the wizard for Import data would be the best start.

 

Is your membered actually a numeric value or character holding digits? This is import as the techniques would differ.

 

If the variable is actually numeric then just use:

id = 9999;

If the membered is character with digits then

 

id = translate(id,'999999999','1234567890');

 

one way to replace the last n characters

 

name = cats(substr(name,1,1),repeat('*',length(substr(name,2))));

 

Personally

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!

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
  • 2 replies
  • 3007 views
  • 0 likes
  • 3 in conversation