<?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 two long digital text strings in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199092#M49733</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am afraid you have to split it into tokens and sum them and combine them after that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;
data have;
txt1= '000350000400321000350000400321000350000400321';
txt2= '000060000200032000060000200032000060000200032';
length txt_sum $ 200;
do i=1 to length(txt1) by 5;
 sum=input(substr(txt1,i,5),best32.)+input(substr(txt2,i,5),best32.);
 txt_sum=cats(txt_sum,put(sum,z5.));
end;
drop sum i;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;XIa Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Mar 2015 15:12:37 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2015-03-11T15:12:37Z</dc:date>
    <item>
      <title>How to add two long digital text strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199086#M49727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;Simplified Example:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;txt1= '000350000400321&lt;SPAN style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;000350000400321&lt;SPAN style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;000350000400321&lt;/SPAN&gt;'&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;txt2= '000060000200032&lt;SPAN style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;000060000200032&lt;SPAN style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;000060000200032&lt;/SPAN&gt;'&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;sum='000410000600353&lt;SPAN style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;000410000600353&lt;SPAN style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;000410000600353' --&amp;gt;Wish to get.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;The example txt strings are strings of individual counts, each occupying 5 digits.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;I need to add each pair of counts in their position.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;In my case, each string is 235 digits long. Informat is limited to 30 or 31 wide.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;where sum=txt1+txt2.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: rgba(0, 0, 0, 0.701961); font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;Of course I can read each count, add them up and re-form the sum string but I wonder if there is another, simpler way such as&lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5em;"&gt;: adding long text strings, converting to integers, Boolean, binary, hex?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2015 13:04:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199086#M49727</guid>
      <dc:creator>Yoram101</dc:creator>
      <dc:date>2015-03-11T13:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two long digital text strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199087#M49728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There's no "pure" solution, since SAS has a limit of 15 to 16 significant digits for numerics.&amp;nbsp; You could try splitting the text into 24 parts, each 10 digits long.&amp;nbsp; SAS would be able to add those.&amp;nbsp; When reassembling the three totals, you would have to account for totals that require 11 digits instead of 10.&amp;nbsp; Your original thought of splitting into 5-digit parts would be just as good.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2015 13:52:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199087#M49728</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-03-11T13:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two long digital text strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199088#M49729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As Astounding has said, it is not directly possible.&amp;nbsp; I remember seeing&amp;nbsp; a post from FriedEgg where he used proc groovy or something along those lines to utilise Java objects to process very large numbers.&amp;nbsp; I would question though why you want to do this.&amp;nbsp; What do those "numbers" actually mean, do you need them as one whole like that, can you not subdivision your data into groups to reduce the size of the number.&amp;nbsp; A number that size is rather rare outside astrological dimensions!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2015 14:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199088#M49729</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-03-11T14:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two long digital text strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199089#M49730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #000000; font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;Each group of records has a header record and a trailer record with record counts by record type. There are at least 17 record type counts in the trailer. Each in an 8 digits field. I want to join 2 groups together and have their total count in a new trailer record.&lt;/P&gt;&lt;P style="color: #000000; font-family: UICTFontTextStyleBody; font-size: 23px;"&gt;This is not my data. I have no control of the data or its format.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2015 14:26:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199089#M49730</guid>
      <dc:creator>Yoram101</dc:creator>
      <dc:date>2015-03-11T14:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two long digital text strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199090#M49731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;However, if it is not possible then I'll have to resort to reading each count separately, add the proper ones, and proceed to reassemble the new trailer with these sums.&lt;/P&gt;&lt;P&gt;thanks for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2015 14:32:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199090#M49731</guid>
      <dc:creator>Yoram101</dc:creator>
      <dc:date>2015-03-11T14:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two long digital text strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199091#M49732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are best off with doing this in a do loop that processes 5 digits per iteration. In the end, the code will basically document itself, making clear that each 5-digit block is a separate entity.&lt;/P&gt;&lt;P&gt;Any "clever" solution could hide that fact and make it harder to decipher what's going on.&lt;/P&gt;&lt;P&gt;In this regard, I think this a typical example for Ken Thompson's "If in doubt, use brute force".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2015 14:41:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199091#M49732</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-03-11T14:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two long digital text strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199092#M49733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am afraid you have to split it into tokens and sum them and combine them after that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;
data have;
txt1= '000350000400321000350000400321000350000400321';
txt2= '000060000200032000060000200032000060000200032';
length txt_sum $ 200;
do i=1 to length(txt1) by 5;
 sum=input(substr(txt1,i,5),best32.)+input(substr(txt2,i,5),best32.);
 txt_sum=cats(txt_sum,put(sum,z5.));
end;
drop sum i;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;XIa Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2015 15:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199092#M49733</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-03-11T15:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two long digital text strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199093#M49734</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Keshan, that is a neat code. Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2015 16:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199093#M49734</guid>
      <dc:creator>Yoram101</dc:creator>
      <dc:date>2015-03-11T16:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two long digital text strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199094#M49735</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;A little bit generalized solution, if one has more than 2 txt# variables and if cannot break all the txt# in regular substrings.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Of course one needs some leading zeros in the txt#'s to be summed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;/*************************/&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;/*** proposed solution ***/&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;/*************************/&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;data have(keep=txt:);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; array txt(3) $45;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; txt1= '000350000400321000350000400321000350000400321';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; txt2= '000060000200032000060000200032000060000200032';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; txt3= '';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; zLeftOver=0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; do i = 1 to 45;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; k=zLeftOver;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do j = 1 to (dim(txt)-1);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; k+input(substr(txt(j),45-i+1,1),1.);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; zLeftOver=int(k/10);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; txt3=cats(mod(k,10),txt3);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2015 22:01:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199094#M49735</guid>
      <dc:creator>billfish</dc:creator>
      <dc:date>2015-03-11T22:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to add two long digital text strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199095#M49736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One gets comfortable programing in a certain way and not until proposing a challenge to our forum that he finds out the many clever ways to skin a cat. This approach comes closest&amp;nbsp; to performing a direct binary add on these text strings.&lt;/P&gt;&lt;P&gt;thanks billfish. Your way is not limited to two strings, does not depend on the text's length, nor on the logical field division within the string. Much appreciated. Thank you all.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Mar 2015 23:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-two-long-digital-text-strings/m-p/199095#M49736</guid>
      <dc:creator>Yoram101</dc:creator>
      <dc:date>2015-03-11T23:08:42Z</dc:date>
    </item>
  </channel>
</rss>

