<?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: Replace all characters with x except last 4 four in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-characters-with-x-except-last-4-four/m-p/893084#M352785</link>
    <description>&lt;P&gt;Assuming that account is a char variable, as it should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;

   if lengthn(account) &amp;gt; 4 then do;
      new = cats(repeat('x', lengthn(account)-5), prxchange('s/.*(.{4})$/$1/', 1, trim(account)));
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 07 Sep 2023 06:37:14 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2023-09-07T06:37:14Z</dc:date>
    <item>
      <title>Replace all characters with x except last 4 four</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-characters-with-x-except-last-4-four/m-p/893062#M352772</link>
      <description>Hello All,&lt;BR /&gt;I have a SAS dataset with account numbers(character). I want to display only last 4 masking the remaining with ‘x’.&lt;BR /&gt;&lt;BR /&gt;Input:&lt;BR /&gt;Account&lt;BR /&gt;123456&lt;BR /&gt;34567898&lt;BR /&gt;&lt;BR /&gt;Output:&lt;BR /&gt;Account&lt;BR /&gt;xx3456&lt;BR /&gt;xxxx7898&lt;BR /&gt;&lt;BR /&gt;Any suggestions will be highly appreciated.</description>
      <pubDate>Thu, 07 Sep 2023 02:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-characters-with-x-except-last-4-four/m-p/893062#M352772</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2023-09-07T02:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all characters with x except last 4 four</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-characters-with-x-except-last-4-four/m-p/893064#M352774</link>
      <description>&lt;P&gt;What do you want if the length of the account is less than or equal to 4 characters?&lt;/P&gt;
&lt;P&gt;Is the Account numeric or character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If account is character valued and leave the account alone if there are 4 or fewer characters:&lt;/P&gt;
&lt;PRE&gt;data have;
input Account :$10.;
datalines;
123456
34567898
1234
;

data want;
   set have;
   if length(account) ge 5 then 
       account = cats(repeat('x',length(account)-5),substr(account,length(account)-3));
run;&lt;/PRE&gt;
&lt;P&gt;Please not the use of a data step to provide some working values. That way we don't have to ask questions like is the Account numeric or character.&lt;/P&gt;
&lt;P&gt;CATS concatenates string values ignoring leading and trailing spaces, Repeat will create the same character a number of times look at the documentation as to why the -5 gets involved.Length returns the number characters excluding trailing spaces. Substr selects a number of characters from a given starting position in the string. If there is no length it uses from the given position to the end of the string. Again look at the values for why -3 is used instead of -4.&lt;/P&gt;
&lt;P&gt;This is only one way.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 03:57:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-characters-with-x-except-last-4-four/m-p/893064#M352774</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-07T03:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all characters with x except last 4 four</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-characters-with-x-except-last-4-four/m-p/893084#M352785</link>
      <description>&lt;P&gt;Assuming that account is a char variable, as it should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;

   if lengthn(account) &amp;gt; 4 then do;
      new = cats(repeat('x', lengthn(account)-5), prxchange('s/.*(.{4})$/$1/', 1, trim(account)));
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Sep 2023 06:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-characters-with-x-except-last-4-four/m-p/893084#M352785</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-09-07T06:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all characters with x except last 4 four</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-characters-with-x-except-last-4-four/m-p/893096#M352793</link>
      <description>&lt;P&gt;Brute force method:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i = 1 to length(account) - 4;
  substr(account,i,1) = "x";
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Sep 2023 08:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-characters-with-x-except-last-4-four/m-p/893096#M352793</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-07T08:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all characters with x except last 4 four</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-characters-with-x-except-last-4-four/m-p/893098#M352795</link>
      <description>&lt;P&gt;If this is/becomes a comon practice at your site, you might want to look into adding masking capabilities to your infrastructure.&lt;/P&gt;
&lt;P&gt;On SAS9 this is managed in Federation Server or DQ/QKB.&lt;/P&gt;
&lt;P&gt;There are also external databases that offers this in the data layer, wich is more flexible than hard rewrite of values.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 08:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-characters-with-x-except-last-4-four/m-p/893098#M352795</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2023-09-07T08:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Replace all characters with x except last 4 four</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-all-characters-with-x-except-last-4-four/m-p/893106#M352801</link>
      <description>&lt;P&gt;You can use a left-hand side SUBSTR to replace characters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;  accnom = accno;
  substr(accnom,1,length(accnom)-4) = repeat('*',length(accnom));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 08:46:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-all-characters-with-x-except-last-4-four/m-p/893106#M352801</guid>
      <dc:creator>RichardAD</dc:creator>
      <dc:date>2023-09-07T08:46:53Z</dc:date>
    </item>
  </channel>
</rss>

