<?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: group sum by non-unique identifier in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/group-sum-by-non-unique-identifier/m-p/849255#M335763</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/108652"&gt;@CHL0320&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your real "HAVE" dataset is grouped appropriately (similar to your sample data) &lt;EM&gt;and&lt;/EM&gt; the leading number in the &lt;FONT face="courier new,courier"&gt;identifier&lt;/FONT&gt; has only one or two digits (so that the first two characters of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;identifier&lt;/FONT&gt; characterize the contiguous observations to be aggregated), then this should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
by id identifier notsorted;
format identifier $2.;
var a;
output out=want(drop=_: identifier) sum=sum_a;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(assuming that the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;sum_a&lt;/FONT&gt; value of the fourth observation in your "WANT" dataset should read 9, not 8&lt;FONT face="helvetica"&gt;)&lt;/FONT&gt;.&lt;/P&gt;</description>
    <pubDate>Mon, 12 Dec 2022 21:04:44 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2022-12-12T21:04:44Z</dc:date>
    <item>
      <title>group sum by non-unique identifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-sum-by-non-unique-identifier/m-p/849244#M335756</link>
      <description>&lt;P&gt;Hi Community,&lt;/P&gt;
&lt;P&gt;I have a dataset that one id with multiple consecutive rows. It starts with the same but not unique identifier (character variable). I want to create a new dataset to collapse other valuess with sum base on the identifier. I have sample dataset as below. The first set of identifiers (in green) and the secone set of identifier (in red) will be in different rows. Thank you for the suggestion and helps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data I have is&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="192"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;id&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;identifier&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;&lt;FONT color="#008000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;&lt;FONT color="#008000"&gt;1.&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;&lt;FONT color="#008000"&gt;7&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;&lt;FONT color="#008000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;&lt;FONT color="#008000"&gt;1.a1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;&lt;FONT color="#008000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;&lt;FONT color="#008000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;&lt;FONT color="#008000"&gt;1.a2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;&lt;FONT color="#008000"&gt;9&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;2.&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;3.&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;4.&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;&lt;FONT color="#FF0000"&gt;1.&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;&lt;FONT color="#FF0000"&gt;2&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;&lt;FONT color="#FF0000"&gt;1.a1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;&lt;FONT color="#FF0000"&gt;6&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;&lt;FONT color="#FF0000"&gt;1.a2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;&lt;FONT color="#FF0000"&gt;4&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;2.&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;2.a1&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;2.a2&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;3.&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;3.a1&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="59.7604px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="71.4792px" height="30px"&gt;4.&lt;/TD&gt;
&lt;TD width="59.7604px" height="30px"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Data want is&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="127px" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.1667px" height="19" style="height: 14.5pt; width: 48pt;"&gt;id&lt;/TD&gt;
&lt;TD width="63.8333px" style="width: 48pt;"&gt;sum_a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.1667px" height="19" align="right" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.8333px" align="right"&gt;&lt;FONT color="#339966"&gt;17&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.1667px" height="19" align="right" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.8333px" align="right"&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.1667px" height="19" align="right" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.8333px" align="right"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.1667px" height="19" align="right" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.8333px" align="right"&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.1667px" height="19" align="right" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.8333px" align="right"&gt;&lt;FONT color="#FF0000"&gt;12&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.1667px" height="19" align="right" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.8333px" align="right"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.1667px" height="19" align="right" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.8333px" align="right"&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="63.1667px" height="19" align="right" style="height: 14.5pt;"&gt;1&lt;/TD&gt;
&lt;TD width="63.8333px" align="right"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 12 Dec 2022 20:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-sum-by-non-unique-identifier/m-p/849244#M335756</guid>
      <dc:creator>CHL0320</dc:creator>
      <dc:date>2022-12-12T20:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: group sum by non-unique identifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-sum-by-non-unique-identifier/m-p/849252#M335761</link>
      <description>&lt;P&gt;It seems to me that if you create a unique identifier, then doing the math is simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */

data have1;
    set have;
    identifier1=scan(identifier,1,'.');
run;
proc summary data=have1 nway;
    class id identifier1;
    var a;
    output out=want sum=sum_a;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code is untested as we need data in SAS data sets (not screen captures, not file attachments). From now on, please provide data as working SAS data step code, which you can type in yourself, or you can create by following &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2022 20:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-sum-by-non-unique-identifier/m-p/849252#M335761</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-12T20:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: group sum by non-unique identifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-sum-by-non-unique-identifier/m-p/849255#M335763</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/108652"&gt;@CHL0320&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your real "HAVE" dataset is grouped appropriately (similar to your sample data) &lt;EM&gt;and&lt;/EM&gt; the leading number in the &lt;FONT face="courier new,courier"&gt;identifier&lt;/FONT&gt; has only one or two digits (so that the first two characters of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;identifier&lt;/FONT&gt; characterize the contiguous observations to be aggregated), then this should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
by id identifier notsorted;
format identifier $2.;
var a;
output out=want(drop=_: identifier) sum=sum_a;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(assuming that the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;sum_a&lt;/FONT&gt; value of the fourth observation in your "WANT" dataset should read 9, not 8&lt;FONT face="helvetica"&gt;)&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2022 21:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-sum-by-non-unique-identifier/m-p/849255#M335763</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-12-12T21:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: group sum by non-unique identifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-sum-by-non-unique-identifier/m-p/849273#M335769</link>
      <description>&lt;P&gt;I would point out that the solution offered by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt; fails if the IDENTIFIER variable has more than two digits before the dot. Perhaps this never happens and isn't worth worrying about, but I thought I would mention it.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2022 23:21:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-sum-by-non-unique-identifier/m-p/849273#M335769</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-12T23:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: group sum by non-unique identifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-sum-by-non-unique-identifier/m-p/849279#M335771</link>
      <description>Thank you so much for the points. It is my pleasure to learn from the masters like you.</description>
      <pubDate>Mon, 12 Dec 2022 22:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-sum-by-non-unique-identifier/m-p/849279#M335771</guid>
      <dc:creator>CHL0320</dc:creator>
      <dc:date>2022-12-12T22:49:46Z</dc:date>
    </item>
  </channel>
</rss>

