<?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: proc sql: multiple conditions at where in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-multiple-conditions-at-where/m-p/717358#M221826</link>
    <description>&lt;P&gt;With SQL you could do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select 
    a.efamid, a.svcDate,
    sum(b.Pay) as totalPay
from
    have as a inner join
    have as b on a.efamid=b.efamid and intck('day', a.svcDate, b.svcDate) between -60 and 90
where a.opCode = "12"
group by a.efamid, a.svcDate;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1612676768221.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54420i54EF966FB02BAAB1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1612676768221.png" alt="PGStats_0-1612676768221.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 07 Feb 2021 05:46:57 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2021-02-07T05:46:57Z</dc:date>
    <item>
      <title>proc sql: multiple conditions at where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-multiple-conditions-at-where/m-p/717342#M221816</link>
      <description>&lt;PRE&gt;I have a dataset below. I would like to find the total payment of each EFAMID. The &lt;BR /&gt;total payment is calculated as Pay during 60 days prior to and 90 days after the service (OpCode=12)&lt;BR /&gt;date. For example, EFAMID=101, the total payment is 10.7 + 18.0 + 10.2 = 38.9 because&lt;BR /&gt;the following observations are within 60 days prior to and 90 days after the &lt;BR /&gt;01/14/2013 (the SvcDate of its OpCode=12).&lt;BR /&gt;&lt;BR /&gt;101 01/13/2013 19 10.7&lt;BR /&gt;101 01/14/2013 12 18.0&lt;BR /&gt;101 04/16/2013 13 10.2&lt;BR /&gt;&lt;BR /&gt;I try to set the filtering conditions at where, but it is not correct. How do I specify&lt;BR /&gt;multiple conditions at where? Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input EFAMID $ SvcDate :mmddyy10. OpCode :$2. Pay;&lt;BR /&gt;format svcdate yymmdd10.;&lt;BR /&gt;datalines;&lt;BR /&gt;101 09/03/2012 10 11.0&lt;BR /&gt;101 01/13/2013 19 10.7&lt;BR /&gt;101 01/14/2013 12 18.0&lt;BR /&gt;101 04/16/2013 13 10.2&lt;BR /&gt;101 11/10/2013 19 10.0&lt;BR /&gt;102 02/10/2013 10 9.7&lt;BR /&gt;102 02/12/2013 12 17.5&lt;BR /&gt;102 02/13/2013 15 10.2&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;  create table want as&lt;BR /&gt;  select a.EFAMID,  &lt;BR /&gt;  (&lt;BR /&gt;    select sum(Pay)&lt;BR /&gt;    from have c&lt;BR /&gt;    where&lt;BR /&gt;      a.EFAMID = c.EFAMID and &lt;BR /&gt;      abs(a.SvcDate - c.SvcDate) le 60 or ((c.SvcDate gt a.SvcDate) and (c.SvcDate - a.SvcDate le 90)) &lt;BR /&gt;  ) as THU&lt;BR /&gt;  from have a&lt;BR /&gt;  where a.opcode = '12'&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Feb 2021 01:37:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-multiple-conditions-at-where/m-p/717342#M221816</guid>
      <dc:creator>sas112</dc:creator>
      <dc:date>2021-02-07T01:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: multiple conditions at where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-multiple-conditions-at-where/m-p/717351#M221822</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/367342"&gt;@sas112&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;I have a dataset below. I would like to find the total payment of each EFAMID. The &lt;BR /&gt;total payment is calculated as Pay during 60 days prior to and 90 days after the service (OpCode=12)&lt;BR /&gt;date. For example, EFAMID=101, the total payment is 10.7 + 18.0 + 10.2 = 38.9 because&lt;BR /&gt;the following observations are within 60 days prior to and 90 days after the &lt;BR /&gt;01/14/2013 (the SvcDate of its OpCode=12).&lt;BR /&gt;&lt;BR /&gt;101 01/13/2013 19 10.7&lt;BR /&gt;101 01/14/2013 12 18.0&lt;BR /&gt;101 04/16/2013 13 10.2&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;I try to set the filtering conditions at where, but it is not correct.&lt;BR /&gt;...&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But 4/16/2013 is NOT within 90 days of the opcode 12 date of 1/14/2013.&amp;nbsp; It is 92 days later, so should not be included in your total for EFAMID 101.&amp;nbsp; &amp;nbsp;If by "it is not correct" you mean your total for 101 is only 28.7, then it &lt;EM&gt;&lt;STRONG&gt;is&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, here is a data step solution.&amp;nbsp; It assumes:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The data are sorted by EFAMID&amp;nbsp; (but not necessarily svcdate within EFAMID)&lt;/LI&gt;
&lt;LI&gt;You never have more than 1 instance of opcode 12 for any id.&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input EFAMID $ SvcDate :mmddyy10. OpCode :$2. Pay;
format svcdate yymmdd10.;
datalines;
101 09/03/2012 10 11.0
101 01/13/2013 19 10.7
101 01/14/2013 12 18.0
101 04/16/2013 13 10.2
101 11/10/2013 19 10.0
102 02/10/2013 10 9.7
102 02/12/2013 12 17.5
102 02/13/2013 15 10.2
;

data want (keep=EFAMID OPCODE12_DATE THU);
  merge have
        have (where=(opcode='12') rename=(svcdate=opcode12_date)) ;
  by efamid;
  if first.efamid then THU=0;

  if (opcode12_date-60) &amp;lt;= svcdate and svcdate &amp;lt;= (opcode12_date+90) then THU+pay;

  if last.efamid;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 04:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-multiple-conditions-at-where/m-p/717351#M221822</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-02-07T04:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: multiple conditions at where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-multiple-conditions-at-where/m-p/717355#M221824</link>
      <description>&lt;P&gt;Thanks for point out&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; But 4/16/2013 is NOT within 90 days of the opcode 12 date of 1/14/2013.&amp;nbsp; It is 92 days later,&amp;nbsp; so should not be included in your total for EFAMID 101.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You are right.&amp;nbsp;4/16/2013 is NOT within 90 days of the opcode 12 date of 1/14/2013.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I need to set the conditions at proc sql since it is just part of my process. Do you have any idea how to specify those conditions at proc sql? Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 05:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-multiple-conditions-at-where/m-p/717355#M221824</guid>
      <dc:creator>sas112</dc:creator>
      <dc:date>2021-02-07T05:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: multiple conditions at where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-multiple-conditions-at-where/m-p/717358#M221826</link>
      <description>&lt;P&gt;With SQL you could do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select 
    a.efamid, a.svcDate,
    sum(b.Pay) as totalPay
from
    have as a inner join
    have as b on a.efamid=b.efamid and intck('day', a.svcDate, b.svcDate) between -60 and 90
where a.opCode = "12"
group by a.efamid, a.svcDate;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1612676768221.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54420i54EF966FB02BAAB1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1612676768221.png" alt="PGStats_0-1612676768221.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 05:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-multiple-conditions-at-where/m-p/717358#M221826</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-02-07T05:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: multiple conditions at where</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-multiple-conditions-at-where/m-p/717409#M221852</link>
      <description>&lt;PRE class="language-sas"&gt;&lt;CODE&gt;intck('day', a.svcDate, b.svcDate) between -60 and 90&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;is what I need. Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 15:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-multiple-conditions-at-where/m-p/717409#M221852</guid>
      <dc:creator>sas112</dc:creator>
      <dc:date>2021-02-07T15:40:05Z</dc:date>
    </item>
  </channel>
</rss>

