<?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: Mask 4 last digits of credit card and apply it in UPDATE statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Mask-4-last-digits-of-credit-card-and-apply-it-in-UPDATE/m-p/894763#M353450</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input  MEZAHE_PART $;
cards;
0009
7100
1040
1323
1417
1610
4732
9340
;
Run;

option cmplib=_null_;
proc fcmp outlib=work.func.math;
function xx(x $) $ 4;
 length encode $ 4;
 do i=1 to lengthn(x);
   encode=cats(encode,byte(rank(  ifc(char(x,i)='9','/',char(x,i))  ) + 1));
 end;
return (encode);
endsub;
run;

option cmplib=work.func varlenchk=nowarn;
proc sql;
update have
 set MEZAHE_PART=xx(MEZAHE_PART) ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 18 Sep 2023 11:30:51 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2023-09-18T11:30:51Z</dc:date>
    <item>
      <title>Mask 4 last digits of credit card and apply it in UPDATE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mask-4-last-digits-of-credit-card-and-apply-it-in-UPDATE/m-p/894684#M353410</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Let's say that I have very big data set with 250 million rows and 30 columns.&lt;/P&gt;
&lt;P&gt;I want to change the value in one&amp;nbsp; char column.&lt;/P&gt;
&lt;P&gt;This column contain only numeric digits but it is character because the meaning is last 4 digits of credit card.(Since it can contain zero's then better to store it as char column).&lt;/P&gt;
&lt;P&gt;The change of value should be done for all rows (No need where clause) and should be done in following way:&lt;/P&gt;
&lt;P&gt;Add one to each digit.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;4732 will be 5843&lt;/P&gt;
&lt;P&gt;9340 will be 0451 (Please note that 9 will become 0)&lt;/P&gt;
&lt;P&gt;I know the way how to do it from other post&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input  MEZAHE_PART $;
cards;
0009
7100
1040
1323
1417
1610
4732
9340
;
Run;

data want;
set have;
do i = 1 to length(mezahe_part);
  if substr(mezahe_part,i,1) = "9"
  then substr(mezahe_part,i,1) = " ";
  else substr(mezahe_part,i,1) = put(sum(1,input(substr(mezahe_part,i,1),1.)),1.);
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My question- How can I do it using UPDATE statement instead of SET statement?&lt;/P&gt;
&lt;P&gt;The DATA step UPDATE operation can read and write data in a single step so it is good advanatage.&lt;/P&gt;
&lt;P&gt;I think that using UPDATE statement will be much more efficient.&lt;/P&gt;
&lt;P&gt;I know the general form of UPDATE statement:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;UPDATE&amp;nbsp; Have&lt;/P&gt;
&lt;P&gt;SET&amp;nbsp;&amp;nbsp;&lt;CODE class=" language-sas"&gt;mezahe_part=.............&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;quit;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;But&amp;nbsp;the&amp;nbsp;question&amp;nbsp;is&amp;nbsp;if&amp;nbsp;there&amp;nbsp;is&amp;nbsp;a&amp;nbsp;way&amp;nbsp;to&amp;nbsp;apply&amp;nbsp;the&amp;nbsp;code&amp;nbsp;of&amp;nbsp;calculate&amp;nbsp;the&amp;nbsp;new&amp;nbsp;value&amp;nbsp;here&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Sep 2023 14:29:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mask-4-last-digits-of-credit-card-and-apply-it-in-UPDATE/m-p/894684#M353410</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-17T14:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: Mask 4 last digits of credit card and apply it in UPDATE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mask-4-last-digits-of-credit-card-and-apply-it-in-UPDATE/m-p/894691#M353415</link>
      <description>&lt;P&gt;Don't bother. No matter what you do, the SAS system will have to read and write all dataset pages anyway.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Sep 2023 17:24:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mask-4-last-digits-of-credit-card-and-apply-it-in-UPDATE/m-p/894691#M353415</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-17T17:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Mask 4 last digits of credit card and apply it in UPDATE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mask-4-last-digits-of-credit-card-and-apply-it-in-UPDATE/m-p/894694#M353418</link>
      <description>So there is no advance of doing it using update statement?</description>
      <pubDate>Sun, 17 Sep 2023 18:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mask-4-last-digits-of-credit-card-and-apply-it-in-UPDATE/m-p/894694#M353418</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-17T18:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: Mask 4 last digits of credit card and apply it in UPDATE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mask-4-last-digits-of-credit-card-and-apply-it-in-UPDATE/m-p/894737#M353439</link>
      <description>&lt;P&gt;The SQL UPDATE is only better when you update a (very) small subset which is found through an index or because of sorting.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2023 05:42:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mask-4-last-digits-of-credit-card-and-apply-it-in-UPDATE/m-p/894737#M353439</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-18T05:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Mask 4 last digits of credit card and apply it in UPDATE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mask-4-last-digits-of-credit-card-and-apply-it-in-UPDATE/m-p/894742#M353443</link>
      <description>&lt;P&gt;PS the DATA step UPDATE statement has a different function, it updates values in one dataset with values from another dataset.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2023 06:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mask-4-last-digits-of-credit-card-and-apply-it-in-UPDATE/m-p/894742#M353443</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-18T06:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: Mask 4 last digits of credit card and apply it in UPDATE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mask-4-last-digits-of-credit-card-and-apply-it-in-UPDATE/m-p/894763#M353450</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input  MEZAHE_PART $;
cards;
0009
7100
1040
1323
1417
1610
4732
9340
;
Run;

option cmplib=_null_;
proc fcmp outlib=work.func.math;
function xx(x $) $ 4;
 length encode $ 4;
 do i=1 to lengthn(x);
   encode=cats(encode,byte(rank(  ifc(char(x,i)='9','/',char(x,i))  ) + 1));
 end;
return (encode);
endsub;
run;

option cmplib=work.func varlenchk=nowarn;
proc sql;
update have
 set MEZAHE_PART=xx(MEZAHE_PART) ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Sep 2023 11:30:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mask-4-last-digits-of-credit-card-and-apply-it-in-UPDATE/m-p/894763#M353450</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-09-18T11:30:51Z</dc:date>
    </item>
  </channel>
</rss>

