<?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 and WHERE statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804950#M317037</link>
    <description>why don't you use "order by".</description>
    <pubDate>Wed, 30 Mar 2022 05:22:31 GMT</pubDate>
    <dc:creator>japelin</dc:creator>
    <dc:date>2022-03-30T05:22:31Z</dc:date>
    <item>
      <title>GROUP and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804944#M317031</link>
      <description>&lt;P&gt;I am trying to get the cost to sum by id and date so that the negative dollars aren't showing in the data.&amp;nbsp; For ex, it's showing as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cost&lt;/P&gt;
&lt;P&gt;741&amp;nbsp; &amp;nbsp; $-241.00&lt;/P&gt;
&lt;P&gt;741&amp;nbsp; &amp;nbsp; $241.00&lt;/P&gt;
&lt;P&gt;741&amp;nbsp; &amp;nbsp; $241.00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is my program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;23 proc sql;&lt;BR /&gt;24 create table claims&lt;BR /&gt;25 as select&lt;BR /&gt;26 memberNo,&lt;BR /&gt;27 planPayer,&lt;BR /&gt;28 claimHeaderId,&lt;BR /&gt;29 rollupeventid,&lt;BR /&gt;30 cpt,&lt;BR /&gt;31 cptdescription,&lt;BR /&gt;32 icd,&lt;BR /&gt;33 icdDescription,&lt;BR /&gt;34 sum(cost) as sumcost,&lt;BR /&gt;35 eventDate,&lt;BR /&gt;36 eventid,&lt;BR /&gt;37 providerNPI,&lt;BR /&gt;38 providerName,&lt;BR /&gt;39 providerSpecialty&lt;BR /&gt;40 from xx.eventLineDetails&lt;BR /&gt;41 where providerSpecialty = 'Dermatology'&lt;BR /&gt;42 and eventDate between "2020-12-01" and "2021-12-31"&lt;BR /&gt;43 and claimatRisk=1&lt;BR /&gt;44 and planPayer not in ('xx')&lt;BR /&gt;45 and cpt like ('J%')&lt;BR /&gt;46 and group by rollupeventid, eventDate;&lt;BR /&gt;__&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &amp;amp;, (, *, **, +, -, '.', /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND,&lt;BR /&gt;BETWEEN, CONTAINS, EQ, EQT, EXCEPT, GE, GET, GROUP, GT, GTT, HAVING, IN, INTERSECT, IS, LE, LET, LIKE, LT, LTT, NE,&lt;BR /&gt;NET, NOT, NOTIN, OR, ORDER, OUTER, UNION, ^, ^=, |, ||, ~, ~=.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 04:01:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804944#M317031</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2022-03-30T04:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804946#M317033</link>
      <description>&lt;P&gt;try fixing below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;delete "and" before "group by".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;group by rollupeventid, eventDate;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 04:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804946#M317033</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-03-30T04:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804947#M317034</link>
      <description>&lt;P&gt;I'm now getting this Note at the bottom: NOTE: The query requires remerging summary statistics back with the original data.&lt;/P&gt;
&lt;P&gt;also, it doesn't look like the sum of cost is accurate because it just lists the positive dollars multiple times but it did remove the negative dollars:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;23 proc sql;&lt;BR /&gt;24 create table claims&lt;BR /&gt;25 as select&lt;BR /&gt;26 memberNo,&lt;BR /&gt;27 planPayer,&lt;BR /&gt;28 claimHeaderId,&lt;BR /&gt;29 rollupeventid,&lt;BR /&gt;30 cpt,&lt;BR /&gt;31 cptdescription,&lt;BR /&gt;32 icd,&lt;BR /&gt;33 icdDescription,&lt;BR /&gt;34 sum(cost) as sumcost,&lt;BR /&gt;35 eventDate,&lt;BR /&gt;36 eventid,&lt;BR /&gt;37 providerNPI,&lt;BR /&gt;38 providerName,&lt;BR /&gt;39 providerSpecialty&lt;BR /&gt;40 from xx.eventLineDetails&lt;BR /&gt;41 where providerSpecialty = 'Dermatology'&lt;BR /&gt;42 and eventDate between "2020-12-01" and "2021-12-31"&lt;BR /&gt;43 and claimatRisk=1&lt;BR /&gt;44 and planPayer not in ('C')&lt;BR /&gt;45 and cpt like ('J%')&lt;BR /&gt;46 group by rollupeventid, eventDate;&lt;BR /&gt;NOTE: The query requires remerging summary statistics back with the original data.&lt;BR /&gt;NOTE: Table WORK.CLAIMS created, with 1523 rows and 14 columns.&lt;/P&gt;
&lt;P&gt;47 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 3.53 seconds&lt;BR /&gt;cpu time 0.13 seconds&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 04:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804947#M317034</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2022-03-30T04:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804948#M317035</link>
      <description>This message is displayed because you are using the sum() function, which is normal&lt;BR /&gt;"The query requires remerging summary statistics back with the original data."&lt;BR /&gt;&lt;BR /&gt;And which code remove the negative dollars?&lt;BR /&gt;&lt;BR /&gt;Also, when writing code, please paste the code itself in the edit window as "SAS code" and post it, not the code output in the log.&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Mar 2022 05:05:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804948#M317035</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-03-30T05:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804949#M317036</link>
      <description>I'm trying to figure out how to sort it so that it is showing the sum of costs per memberno, per eventDate.  &lt;BR /&gt;&lt;BR /&gt;Would I have to create another data step?</description>
      <pubDate>Wed, 30 Mar 2022 05:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804949#M317036</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2022-03-30T05:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804950#M317037</link>
      <description>why don't you use "order by".</description>
      <pubDate>Wed, 30 Mar 2022 05:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804950#M317037</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-03-30T05:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804951#M317038</link>
      <description>&lt;P&gt;Do you know how I can sum the cost per memberno, per eventdate??&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 05:27:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804951#M317038</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2022-03-30T05:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804954#M317041</link>
      <description>&lt;P&gt;&lt;BR /&gt;Why not use these code instead?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;group by memberno, eventdate
order by memberno, eventdate&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Mar 2022 05:36:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804954#M317041</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-03-30T05:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804964#M317048</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@anonymous_user&amp;nbsp;wrote:&lt;BR /&gt;I'm trying to figure out how to sort it so that it is showing the sum of costs per memberno, per eventDate. &lt;BR /&gt;&lt;BR /&gt;Would I have to create another data step?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is a very simple SQL query:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table claims as
  select
    memberno,
    eventdate,
    sum(cost) as sumcost
  from xx.eventlinedetails
  group by memberno, eventdate
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but SAS provides procedures for such tasks:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=xx.eventlinedetails nway;
class memberno eventdate;
var cost;
output
  out=claims
  sum(cost)=sumcost
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Mar 2022 06:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804964#M317048</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-30T06:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804985#M317059</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;I tried the bottom one and the negative amounts came back into the data:

proc means data=claims nway;
class memberNo eventDate claimHeaderId cpt cptdescription icd icdDescription;
var cost;
output
  out=claims2
  sum(cost)=sumcost
;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is the output (but the negative amounts should be gone):&lt;/P&gt;
&lt;TABLE width="1170"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="122"&gt;memberNo&lt;/TD&gt;
&lt;TD width="73"&gt;eventDate&lt;/TD&gt;
&lt;TD width="98"&gt;claimHeaderId&lt;/TD&gt;
&lt;TD width="40"&gt;cpt&lt;/TD&gt;
&lt;TD width="212"&gt;cptDescription&lt;/TD&gt;
&lt;TD width="66"&gt;icd&lt;/TD&gt;
&lt;TD width="398"&gt;icdDescription&lt;/TD&gt;
&lt;TD width="50"&gt;_TYPE_&lt;/TD&gt;
&lt;TD width="53"&gt;_FREQ_&lt;/TD&gt;
&lt;TD width="58"&gt;sumcost&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;2021-06-30&lt;/TD&gt;
&lt;TD&gt;111&lt;/TD&gt;
&lt;TD&gt;Jxxxx&lt;/TD&gt;
&lt;TD&gt;xxxx&lt;/TD&gt;
&lt;TD&gt;xxxx&lt;/TD&gt;
&lt;TD&gt;xxxxx&lt;/TD&gt;
&lt;TD&gt;127&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;-$2.06&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;456&lt;/TD&gt;
&lt;TD&gt;2020-12-30&lt;/TD&gt;
&lt;TD&gt;333&lt;/TD&gt;
&lt;TD&gt;Jxxxx&lt;/TD&gt;
&lt;TD&gt;xxxx&lt;/TD&gt;
&lt;TD&gt;xxx&lt;/TD&gt;
&lt;TD&gt;xxxxx&lt;/TD&gt;
&lt;TD&gt;127&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;-$1.86&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 30 Mar 2022 08:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804985#M317059</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2022-03-30T08:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804991#M317064</link>
      <description>&lt;P&gt;If you want to filter negative results, use a WHERE= dataset option on the output. If you want to filter negative values, do so on the input dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 09:25:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-and-WHERE-statements/m-p/804991#M317064</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-30T09:25:29Z</dc:date>
    </item>
  </channel>
</rss>

