<?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 do I sum rows of a column based on 2 other column values? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-sum-rows-of-a-column-based-on-2-other-column-values/m-p/806668#M317860</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select id1, id2, sum(length) as length
from have 
group by id1, id2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 07 Apr 2022 22:11:30 GMT</pubDate>
    <dc:creator>tarheel13</dc:creator>
    <dc:date>2022-04-07T22:11:30Z</dc:date>
    <item>
      <title>How do I sum rows of a column based on 2 other column values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-sum-rows-of-a-column-based-on-2-other-column-values/m-p/806598#M317827</link>
      <description>&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID1&lt;/TD&gt;&lt;TD&gt;ID2&lt;/TD&gt;&lt;TD&gt;Length&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A_001&lt;/TD&gt;&lt;TD&gt;A_005&lt;/TD&gt;&lt;TD&gt;450&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A_001&lt;/TD&gt;&lt;TD&gt;A_005&lt;/TD&gt;&lt;TD&gt;600&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A_001&lt;/TD&gt;&lt;TD&gt;A_005&lt;/TD&gt;&lt;TD&gt;700&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A_001&lt;/TD&gt;&lt;TD&gt;A_006&lt;/TD&gt;&lt;TD&gt;350&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A_001&lt;/TD&gt;&lt;TD&gt;A_006&lt;/TD&gt;&lt;TD&gt;800&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A_005&lt;/TD&gt;&lt;TD&gt;A_006&lt;/TD&gt;&lt;TD&gt;900&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A_005&lt;/TD&gt;&lt;TD&gt;A_006&lt;/TD&gt;&lt;TD&gt;750&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi all, I am very new to SAS.&amp;nbsp; I have a data table of comparisons between 2 different IDs (found in columns 1 and 2), and the lengths shared between them.&amp;nbsp; &amp;nbsp;There are multiple lengths listed for these different pairs.&amp;nbsp; I want the sum of lengths for each of the matching pairs and to output that as a separate data table.&amp;nbsp; See the example below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID1&lt;/TD&gt;&lt;TD&gt;ID2&lt;/TD&gt;&lt;TD&gt;Length&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A_001&lt;/TD&gt;&lt;TD&gt;A_005&lt;/TD&gt;&lt;TD&gt;1750&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A_001&lt;/TD&gt;&lt;TD&gt;A_006&lt;/TD&gt;&lt;TD&gt;1150&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A_005&lt;/TD&gt;&lt;TD&gt;A_006&lt;/TD&gt;&lt;TD&gt;1650&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I accomplish this in SAS?&amp;nbsp; I honestly have no idea where even to start.&amp;nbsp; I appreciate any advice!&amp;nbsp; I am working in SAS 9.4.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 17:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-sum-rows-of-a-column-based-on-2-other-column-values/m-p/806598#M317827</guid>
      <dc:creator>SAS49</dc:creator>
      <dc:date>2022-04-07T17:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I sum rows of a column based on 2 other column values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-sum-rows-of-a-column-based-on-2-other-column-values/m-p/806599#M317828</link>
      <description>&lt;P&gt;I would let PROC SUMMARY have all the fun.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
    class id1 id2;
    var length;
    output out=want sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Apr 2022 17:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-sum-rows-of-a-column-based-on-2-other-column-values/m-p/806599#M317828</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-07T17:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I sum rows of a column based on 2 other column values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-sum-rows-of-a-column-based-on-2-other-column-values/m-p/806668#M317860</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select id1, id2, sum(length) as length
from have 
group by id1, id2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Apr 2022 22:11:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-sum-rows-of-a-column-based-on-2-other-column-values/m-p/806668#M317860</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-04-07T22:11:30Z</dc:date>
    </item>
  </channel>
</rss>

