<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to mask Numbers in a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605756#M175813</link>
    <description>&lt;P&gt;This is possibly one of the few times it might make sense to use numeric variables instead of character variables for account id's. &amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; 's suggestion allows you to keep actual ACCT values for subsequent matching purposes, while masking a trailing digits when the variable is displayed.&amp;nbsp; Of course, this approach is really only effective when those data consumers unauthorized to see the actual values don't have direct access to the data variable being formatted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The trade-off in&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; 's suggestion is that once the character variable ACCT has been changed (replacing trailing characters with XXXXX), it may no longer be&amp;nbsp; specific (in fact making it non-specific is the point).&amp;nbsp; Not only will the modified value no longer be useable as a match key, it could easily create false duplicates within the data set - say if you want the average number of records per account.&amp;nbsp; So make sure you do all your data aggregation and matching prior to any report generation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Nov 2019 14:50:06 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2019-11-20T14:50:06Z</dc:date>
    <item>
      <title>How to mask Numbers in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605719#M175802</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on a sas dataset which have account numbers. I want to mask the last 5 digits of the Number with "X";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the dataset;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test;&lt;/P&gt;&lt;P&gt;input acct;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;676869845614567&lt;/P&gt;&lt;P&gt;7689645983&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;acct&lt;/P&gt;&lt;P&gt;6768698456XXXX&lt;/P&gt;&lt;P&gt;76896XXXXX&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please suggest any approach&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sanjay&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 13:16:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605719#M175802</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2019-11-20T13:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to mask Numbers in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605724#M175804</link>
      <description>&lt;P&gt;Do you want to change the actual values or simply apply a format that masks the last 5 digits?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 13:23:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605724#M175804</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-20T13:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to mask Numbers in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605727#M175806</link>
      <description>&lt;P&gt;If you're looking for a format solution, then do&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    picture mask (default=15)
        other = '0000000000XXXXX' (mult=0.00001);
run;

data test;
    value=676869845614567;output;
    value=7689645983; output;
    format value mask.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;value
6768698456XXXXX
76896XXXXX&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Nov 2019 13:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605727#M175806</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-20T13:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to mask Numbers in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605731#M175807</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91059"&gt;@sanjay1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try this&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set test;
	acct_new = compress(put(acct,20.));
	substr(acct_new,length(acct_new)-4) = "XXXXX";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(NB: the put() function is not useful if the act variable type is already character.)&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 13:38:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605731#M175807</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-11-20T13:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to mask Numbers in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605733#M175809</link>
      <description>&lt;P&gt;Account numbers are not numbers per se, as they are not used for calculations. Therefore store them as character.&lt;/P&gt;
&lt;P&gt;Then masking is quite easy:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input acct :$20.;
cards;
676869845614567
7689645983
;
run;

data want;
set have;
substr(acct,length(acct)-4) = 'XXXXX';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Nov 2019 13:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605733#M175809</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-20T13:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to mask Numbers in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605756#M175813</link>
      <description>&lt;P&gt;This is possibly one of the few times it might make sense to use numeric variables instead of character variables for account id's. &amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; 's suggestion allows you to keep actual ACCT values for subsequent matching purposes, while masking a trailing digits when the variable is displayed.&amp;nbsp; Of course, this approach is really only effective when those data consumers unauthorized to see the actual values don't have direct access to the data variable being formatted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The trade-off in&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; 's suggestion is that once the character variable ACCT has been changed (replacing trailing characters with XXXXX), it may no longer be&amp;nbsp; specific (in fact making it non-specific is the point).&amp;nbsp; Not only will the modified value no longer be useable as a match key, it could easily create false duplicates within the data set - say if you want the average number of records per account.&amp;nbsp; So make sure you do all your data aggregation and matching prior to any report generation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 14:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605756#M175813</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-11-20T14:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to mask Numbers in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605760#M175817</link>
      <description>&lt;P&gt;If the goal was just to mask account IDs for output, my method would be sufficient. If the goal is to anonymize the data and keep it usable, then a surrogate key needs to be created.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 14:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605760#M175817</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-20T14:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to mask Numbers in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605763#M175820</link>
      <description>Agreed</description>
      <pubDate>Wed, 20 Nov 2019 15:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605763#M175820</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-11-20T15:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to mask Numbers in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605805#M175830</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;I agree.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91059"&gt;@sanjay1&lt;/a&gt;&amp;nbsp;If value is really character and you do not want to alter the actual value, you can still do this, though it requires a bit more work and the code is not as slick&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.functions.fun; 
   function mask(string $) $;
      substr(string,max(1, length(string)-4),5)='XXXXX';
      return (string);
   endsub;
run;

options cmplib=work.functions;
proc format;
    value $ mask (default=200) other=[mask()];
run;

data test;
   value='676869845614567'; output;
   value='7689645983'; output;
 
   format value $mask.;
run;
 
proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Nov 2019 15:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605805#M175830</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-20T15:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to mask Numbers in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605913#M175886</link>
      <description>&lt;P&gt;Just for completeness sake:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input acct :$20.;
cards;
676869845614567
7689645983
1234
;

data want;
set have;
masked = prxchange("s/\d{5}\s*$/XXXXX/o", 1, acct);
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs. 	acct 	masked
1 	676869845614567 	6768698456XXXXX
2 	7689645983 	76896XXXXX
3 	1234 	1234&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Nov 2019 19:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-mask-Numbers-in-a-variable/m-p/605913#M175886</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-11-20T19:56:05Z</dc:date>
    </item>
  </channel>
</rss>

