<?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: SUM by ID and date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804969#M317053</link>
    <description>Yes, sum by id and eventDate.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 30 Mar 2022 06:48:38 GMT</pubDate>
    <dc:creator>anonymous_user</dc:creator>
    <dc:date>2022-03-30T06:48:38Z</dc:date>
    <item>
      <title>SUM by ID and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804965#M317049</link>
      <description>&lt;P&gt;I'm trying to get rid of negative dollar amounts in my data. For ex:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cost&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;eventDate&lt;/P&gt;
&lt;P&gt;741&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -$241.00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2021-10-21&lt;/P&gt;
&lt;P&gt;741&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$241.00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2021-10-21&lt;/P&gt;
&lt;P&gt;741&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$241.00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2021-11-20&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to sum by ID and by date so that it looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cost&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;eventDate&lt;/P&gt;
&lt;P&gt;741&amp;nbsp; &amp;nbsp; &amp;nbsp; $0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2021-10-21&lt;/P&gt;
&lt;P&gt;741&amp;nbsp; &amp;nbsp; &amp;nbsp;$241.00&amp;nbsp; &amp;nbsp; &amp;nbsp;2021-11-20&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table claims&lt;BR /&gt;as select &lt;BR /&gt;memberNo,&lt;BR /&gt;planPayer,&lt;BR /&gt;claimHeaderId,&lt;BR /&gt;rollupeventid,&lt;BR /&gt;cpt,&lt;BR /&gt;cptdescription,&lt;BR /&gt;icd,&lt;BR /&gt;icdDescription,&lt;BR /&gt;cost,&lt;BR /&gt;eventDate,&lt;BR /&gt;eventid,&lt;BR /&gt;providerNPI,&lt;BR /&gt;providerName,&lt;BR /&gt;providerSpecialty&lt;BR /&gt;from xx.eventLineDetails&lt;BR /&gt;where providerSpecialty = 'Dermatology'&lt;BR /&gt;and eventDate between "2020-12-01" and "2021-12-31"&lt;BR /&gt;and claimatRisk=1&lt;BR /&gt;and planPayer not in ('C') &lt;BR /&gt;and cpt like ('J%');&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 06:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804965#M317049</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2022-03-30T06:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: SUM by ID and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804967#M317051</link>
      <description>&lt;P&gt;Do you simply want to delete observations with a begative dollar amount? You example seems more like you want to sum the amounts grouped by ID and EventDate?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please be more specific.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 06:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804967#M317051</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-03-30T06:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: SUM by ID and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804969#M317053</link>
      <description>Yes, sum by id and eventDate.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Mar 2022 06:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804969#M317053</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2022-03-30T06:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: SUM by ID and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804970#M317054</link>
      <description>&lt;P&gt;Then do&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id cost :dollar8.2 eventDate :yymmdd10.;
format cost dollar8.2 eventDate yymmdd10.;
datalines;
741 -$241.00 2021-10-21
741  $241.00 2021-10-21
741  $241.00 2021-11-20
;

proc summary data = have nway;
   class id eventDate;
   var cost;
   output out = want(drop = _:) sum =;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Mar 2022 06:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804970#M317054</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-03-30T06:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: SUM by ID and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804971#M317055</link>
      <description>&lt;P&gt;For building a sum, see my answer here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804964/highlight/true#M317048" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804964/highlight/true#M317048&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what are the many other variables in your SQL query? To really help you, we need example data (post it as a data step with datalines into a code box, &lt;FONT color="#FF0000"&gt;do not skip this!!&lt;/FONT&gt;) and what you expect as a result out of that.&lt;/P&gt;
&lt;P&gt;If you want to do a sum in SQL, all variables in the select must be&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;part of the GROUP BY clause&lt;/LI&gt;
&lt;LI&gt;or the result of a SQL summary function&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;or you will get a "remerge", where the original observations are all kept and each receives the sum over the group.&lt;/P&gt;
&lt;P&gt;So it is important to know the roles of all your other variables. If, say, they are constant for a memberno and/or eventdate, then you need to include them all in the GROUP BY. If not, you need to decide which values for a given memberno/eventdate should take precedence in the result.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 06:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804971#M317055</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-30T06:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: SUM by ID and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804981#M317058</link>
      <description>This did get rid of the negative dollar amounts, but if I wanted to add other fields like below, the negative dollar amounts come back.  Is there a way to remove those negatives with these extra fields added? &lt;BR /&gt;&lt;BR /&gt;proc summary data = claims nway;&lt;BR /&gt;   class memberNo eventDate claimHeaderId cpt cptDescription icd icdDescription;&lt;BR /&gt;   var cost;&lt;BR /&gt;   output out = claims2(drop = _:) sum =;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 30 Mar 2022 08:26:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804981#M317058</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2022-03-30T08:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: SUM by ID and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804990#M317063</link>
      <description>Calculate your own analysis variable.  Instead of COST, use&lt;BR /&gt;&lt;BR /&gt;max(cost, 0) as poscost</description>
      <pubDate>Wed, 30 Mar 2022 09:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804990#M317063</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-03-30T09:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: SUM by ID and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804992#M317065</link>
      <description>&lt;P&gt;Example data.&lt;/P&gt;
&lt;P&gt;Example data.&lt;/P&gt;
&lt;P&gt;Example data.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 09:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUM-by-ID-and-date/m-p/804992#M317065</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-30T09:27:04Z</dc:date>
    </item>
  </channel>
</rss>

