<?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 add digits of alphanumeric field in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665013#M22891</link>
    <description>&lt;P&gt;357=345+(3+5+7)&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jun 2020 13:50:41 GMT</pubDate>
    <dc:creator>Trishjais</dc:creator>
    <dc:date>2020-06-25T13:50:41Z</dc:date>
    <item>
      <title>How to add digits of alphanumeric field</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/664978#M22887</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
&lt;P&gt;I have got a request to transform alphanumeric field in a way that we are summing up the digits and adding to the numbers as below. Any characters on the left of the number is advanced by 2 position as per English alphabet (A-Z-A) , characters on the right of the number is lowered to one position, then numbers sandwiched in characters are added up in original number, as per below example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Length of the value field could be max of 20 .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="182"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Value&lt;/TD&gt;
&lt;TD width="118"&gt;Transformed value&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;AB345C&lt;/TD&gt;
&lt;TD&gt;DE357B&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;P75EF&lt;/TD&gt;
&lt;TD&gt;S87E&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Z7869Q&lt;/TD&gt;
&lt;TD&gt;C7899P&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1169893&lt;/TD&gt;
&lt;TD&gt;1169893&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your help is really appreciated&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 12:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/664978#M22887</guid>
      <dc:creator>Trishjais</dc:creator>
      <dc:date>2020-06-25T12:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to add digits of alphanumeric field</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/664979#M22888</link>
      <description>Please refer updated table.&lt;BR /&gt;&lt;BR /&gt;Value	Transformed value&lt;BR /&gt;AB345C	DE357B&lt;BR /&gt;P75EF	S87DE&lt;BR /&gt;Z7869Q	C7899P&lt;BR /&gt;1169893	1169893&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Jun 2020 12:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/664979#M22888</guid>
      <dc:creator>Trishjais</dc:creator>
      <dc:date>2020-06-25T12:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to add digits of alphanumeric field</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665005#M22889</link>
      <description>&lt;P&gt;What is the formula for getting&lt;/P&gt;
&lt;P&gt;from 345 to 357&lt;/P&gt;
&lt;P&gt;from 75 to 87&lt;/P&gt;
&lt;P&gt;from 7869 to 7899&lt;/P&gt;
&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 13:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665005#M22889</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-25T13:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to add digits of alphanumeric field</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665010#M22890</link>
      <description>&lt;P&gt;I guess: If old number is surrounded by letters, then new number = old number + sum of digits of old number.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 13:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665010#M22890</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-06-25T13:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to add digits of alphanumeric field</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665013#M22891</link>
      <description>&lt;P&gt;357=345+(3+5+7)&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 13:50:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665013#M22891</guid>
      <dc:creator>Trishjais</dc:creator>
      <dc:date>2020-06-25T13:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to add digits of alphanumeric field</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665014#M22892</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/242585"&gt;@Trishjais&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;357=345+(3+5+7)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Almost.&lt;/P&gt;
&lt;P&gt;357=345+(3+&lt;STRONG&gt;4&lt;/STRONG&gt;+5)&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 13:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665014#M22892</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-06-25T13:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to add digits of alphanumeric field</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665016#M22893</link>
      <description>&lt;P&gt;Next code may result differently according to local "ascii" sequence.&lt;/P&gt;
&lt;P&gt;Try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   infile datalines;
   input string $20.;
datalines;
AB345C  
P75EF  
Z7869Q  
1169893  
; run;

data want;
 set have;
     length cx $1 new_str $20; 
     phase=0;
     L = length(string); put L=;
     number = input(compress(string,' ','kd'),best20.); 
     new_num = number;
     new_str = repeat(' ',19);
     do i=1 to L;
        cx = substr(string,i,1);
        if cx &amp;gt; '9' then do;  /* assuming all digits precede alphbetic characters */
           if phase=0 then do;
              if cx = 'Z' and pahse=1 then substr(new_str,i,1) = 'B'; else
              substr(new_str,i,1) = byte(rank(cx)+2); 
           end; else
		   if phase=2 then do;
              if cx = 'A' then substr(new_str,i,1) = 'Z'; else
		      substr(new_str,i,1) = byte(rank(cx)-1); 
		   end;
		end;
		else if ('0' le cx le '9') then do;
		   phase=1;
		   do j=i to L;
		      cx = substr(string,j,1);
		      if cx &amp;gt; '9' then leave;
			  new_num = new_num + input(cx,1.); 
		   end;
		   new_str = cats(new_str,left(new_num));  put new_str=;
		   phase=2;
		   i = j;
           if cx = 'A' then substr(new_str,i,1) = 'Z'; else
		   substr(new_str,i,1) = byte(rank(cx)-1); 
		   leave;
		 end;
	end;
	new_str = strip(new_str);
	DROP i j ;
run;	   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;At row 2, assuming letter sequience is '...P Q R ...' then new string should start with R and not S as you displayed.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 14:00:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665016#M22893</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-06-25T14:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to add digits of alphanumeric field</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665022#M22894</link>
      <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input instring :$20. want :$20.;
datalines;
AB345C DE357B
P75EF S87E
Z7869Q C7899P
1169893 1169893
;

data want;
set have;
ff = anydigit(instring);
if ff in (1,0)
then outstring = instring;
else do;
  do i = 1 to ff - 1;
    outstring = cats(outstring,byte(mod(rank(char(instring,i))-64+3,26)+64));
  end;
  fl = anyalpha(instring,ff+1);
  num = input(substr(instring,ff,fl-ff),best.);
  do i = ff to fl - 1;
    num = num + input(char(instring,i),1.);
  end;
  outstring=cats(outstring,put(num,best.));
  do i = fl to length(instring);
    outstring = cats(outstring,byte(mod(rank(char(instring,i))-64-1,26)+64));
  end;
end;
drop i ff fl num;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jun 2020 14:17:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665022#M22894</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-25T14:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to add digits of alphanumeric field</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665101#M22902</link>
      <description>&lt;P&gt;Hello Kurt,&lt;/P&gt;
&lt;P&gt;Many thanks for your response, apologizes, I forgot to add the digits on the fourth row. your solution is working perfectly fine except for the last as it was my mistake. I forgot to add digits for the last case. please see below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="266"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Value&lt;/TD&gt;
&lt;TD width="202"&gt;Transformed value&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;AB345C&lt;/TD&gt;
&lt;TD width="202"&gt;DE357B&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;P75EF&lt;/TD&gt;
&lt;TD width="202"&gt;S87DE&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Z7869Q&lt;/TD&gt;
&lt;TD width="202"&gt;C7899P&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;1169893&lt;/TD&gt;
&lt;TD width="202"&gt;1169930&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be great if you can help with this.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 17:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665101#M22902</guid>
      <dc:creator>Trishjais</dc:creator>
      <dc:date>2020-06-25T17:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to add digits of alphanumeric field</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665117#M22903</link>
      <description>&lt;P&gt;After editing my code it results as wanted:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   infile datalines;
   input string $20.;
datalines;
AB345C  
P75EF  
Z7869Q  
1169893  
; run;

data want;
 set have;
     length cx $1 new_str $20; 
     phase=0;
     L = length(string); put L=;
     number = input(compress(string,' ','kd'),best20.); 
     new_num = number;
     new_str = repeat(' ',19);
     do i=1 to L;
        cx = substr(string,i,1);
        if cx &amp;gt; '9' then do;  /* assuming all digits precede alphbetic characters */
           if phase=0 then do;
              if cx = 'Z' then substr(new_str,i,1) = 'C'; else
              substr(new_str,i,1) = byte(rank(cx)+3); 
           end; else
		   if phase=2 then do;
              if cx = 'A' then substr(new_str,i,1) = 'Z'; else
		      substr(new_str,i,1) = byte(rank(cx)-1); 
		   end;
		end;
		else if ('0' le cx le '9') then do;
		   phase=1;
		   do j=i to L;
		      cx = substr(string,j,1);
		      if cx &amp;gt; '9' then leave;
			  new_num = new_num + input(cx,1.); 
		   end;
		   new_str = cats(new_str,left(new_num));  
		   phase=2;
		   i = j;
           if cx = 'A' then substr(new_str,i,1) = 'Z'; else
		   if cx &amp;gt; '9' then substr(new_str,i,1) = byte(rank(cx)-1); 
		   *leave;
		 end;
	end;
	new_str = strip(new_str);
	keep string new_str;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jun 2020 18:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665117#M22903</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-06-25T18:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to add digits of alphanumeric field</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665444#M22914</link>
      <description>Thanks</description>
      <pubDate>Fri, 26 Jun 2020 19:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/665444#M22914</guid>
      <dc:creator>angelojun2k</dc:creator>
      <dc:date>2020-06-26T19:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to add digits of alphanumeric field</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/666283#M22973</link>
      <description>&lt;P&gt;Just for completeness: revised code that deals with a pure numeric value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input instring :$20. want :$20.;
datalines;
AB345C DE357B
P75EF S87E
Z7869Q C7899P
1169893 1169893
;

data want;
set have;
length outstring $20;
ff = anydigit(instring);
do i = 1 to ff - 1;
  outstring = cats(outstring,byte(mod(rank(char(instring,i))-64+3,26)+64));
end;
fl = anyalpha(instring,ff+1);
if fl = 0 then fl = length(instring) + 1;
num = input(substr(instring,max(ff,1),fl-ff),best.);
do i = max(ff,1) to fl - 1;
  num = num + input(char(instring,i),1.);
end;
outstring=cats(outstring,put(num,best.));
do i = fl to length(instring);
  outstring = cats(outstring,byte(mod(rank(char(instring,i))-64-1,26)+64));
end;
drop i ff fl num;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Jul 2020 07:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-add-digits-of-alphanumeric-field/m-p/666283#M22973</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-01T07:09:39Z</dc:date>
    </item>
  </channel>
</rss>

