BookmarkSubscribeRSS Feed
gsreddy
Fluorite | Level 6

Hi All,

Do we have any function in SAS to mask the numbers?

 

i Have a variable name Ph_num like below:

 

Input:

 

Ph_Num:

9876543210

 

required Output:

98765xxxxx

 

 

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What are the rules for masking as:

want=cats(substr(ph_num,1,5),repeat('x',lengthn(ph_num)-5));

Should work for your given example.  Or you could loop over the string etc.

gamotte
Rhodochrosite | Level 12

Hello,

 

I'm not very at ease with picture formats but i think this works :

 

proc format;
    picture mask
        0-9999999999 ='99999XXXXX' (mult=0.00001);
run;

data _null_;
    format a b mask.;
    a=9876543210;
    b=0012345678;
    put a= b=;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

The only thing I would say there is that it doesn't change the underlying data, take the format away and the number displays as before.

gamotte
Rhodochrosite | Level 12
Yes, it depends whether the goal is to store masked number or only use masks for publications. If the latter, using a format can be a solution.

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