<?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 determine min rate in the past 36 days in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-determine-min-rate-in-the-past-36-days/m-p/49006#M13276</link>
    <description>I do not think sub-query will be more efficient than cartesian product.&lt;BR /&gt;
So I used Cartesian Product.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
input Product $ Treatment $ Date : yymmdd12. Rate ;&lt;BR /&gt;
format date yymmdd10.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
Mortgage High 2011-02-28 2.29 &lt;BR /&gt;
Mortgage High 2011-03-01 2.19 &lt;BR /&gt;
Mortgage High 2011-03-02 2.09 &lt;BR /&gt;
Mortgage Med 2011-02-28 3.29 &lt;BR /&gt;
Mortgage Med 2011-03-01 3.19 &lt;BR /&gt;
Mortgage Med 2011-03-02 3.09 &lt;BR /&gt;
Mortgage Low 2011-02-28 4.29 &lt;BR /&gt;
Mortgage Low 2011-03-01 4.19 &lt;BR /&gt;
Mortgage Low 2011-03-02 4.09 &lt;BR /&gt;
Mortgage Low 2011-03-03 4.99 &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table min_rate as&lt;BR /&gt;
 select a.*,min(b.rate) as min_rate&lt;BR /&gt;
  from temp as a,temp as b&lt;BR /&gt;
   where a.product = b.product and a.treatment = b.treatment&lt;BR /&gt;
         and b.date between a.date-1 and a.date &lt;BR /&gt;
     group by a.product,a.treatment,a.date,a.rate&lt;BR /&gt;
   ;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Wed, 13 Apr 2011 03:42:05 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-04-13T03:42:05Z</dc:date>
    <item>
      <title>PROC SQL determine min rate in the past 36 days</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-determine-min-rate-in-the-past-36-days/m-p/49004#M13274</link>
      <description>I am trying to build a query to determine the min rate in the past 36 days.&lt;BR /&gt;
&lt;BR /&gt;
for this example, I will only specify 2 days to make the example small.&lt;BR /&gt;
&lt;BR /&gt;
For this example I need to check each row in the following table and determine the minimum rate for each group of records for the past 2 days. &lt;BR /&gt;
&lt;BR /&gt;
In reality I need to check the past 36 days...&lt;BR /&gt;
&lt;BR /&gt;
Product   Treatment  Date           Rate    Min-Rate&lt;BR /&gt;
====================================&lt;BR /&gt;
&lt;BR /&gt;
Mortgage High          2011-02-28  2.29    2.29 &lt;BR /&gt;
Mortgage High          2011-03-01  2.19    2.19 &lt;BR /&gt;
Mortgage High          2011-03-02  2.09    2.09 &lt;BR /&gt;
&lt;BR /&gt;
Mortgage Med          2011-02-28  3.29    3.29 &lt;BR /&gt;
Mortgage Med          2011-03-01  3.19    3.19 &lt;BR /&gt;
Mortgage Med          2011-03-02  3.09    3.09 &lt;BR /&gt;
&lt;BR /&gt;
Mortgage Low           2011-02-28  4.29    4.29 &lt;BR /&gt;
Mortgage Low           2011-03-01  4.19    4.19 &lt;BR /&gt;
Mortgage Low           2011-03-02  4.09    4.09 &lt;BR /&gt;
Mortgage Low           2011-03-03  4.99    4.09 &lt;BR /&gt;
&lt;BR /&gt;
For each date record, I need to examine the past &lt;BR /&gt;
2 days and determine the minimum rate within each&lt;BR /&gt;
group ( Mortgage High, Mortgage Med, Mortgage Low )&lt;BR /&gt;
 &lt;BR /&gt;
I think I may need to use a subquery, but not sure on&lt;BR /&gt;
the coding, &lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Tue, 12 Apr 2011 23:45:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-determine-min-rate-in-the-past-36-days/m-p/49004#M13274</guid>
      <dc:creator>wildhogs</dc:creator>
      <dc:date>2011-04-12T23:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL determine min rate in the past 36 days</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-determine-min-rate-in-the-past-36-days/m-p/49005#M13275</link>
      <description>proc sql;&lt;BR /&gt;
select product, treatment, min(rate) as Min_Rate&lt;BR /&gt;
from work.data&lt;BR /&gt;
where date &amp;gt;= (date()-36)&lt;BR /&gt;
group by product, treatment;&lt;BR /&gt;
quit;</description>
      <pubDate>Wed, 13 Apr 2011 03:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-determine-min-rate-in-the-past-36-days/m-p/49005#M13275</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-04-13T03:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL determine min rate in the past 36 days</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-determine-min-rate-in-the-past-36-days/m-p/49006#M13276</link>
      <description>I do not think sub-query will be more efficient than cartesian product.&lt;BR /&gt;
So I used Cartesian Product.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
input Product $ Treatment $ Date : yymmdd12. Rate ;&lt;BR /&gt;
format date yymmdd10.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
Mortgage High 2011-02-28 2.29 &lt;BR /&gt;
Mortgage High 2011-03-01 2.19 &lt;BR /&gt;
Mortgage High 2011-03-02 2.09 &lt;BR /&gt;
Mortgage Med 2011-02-28 3.29 &lt;BR /&gt;
Mortgage Med 2011-03-01 3.19 &lt;BR /&gt;
Mortgage Med 2011-03-02 3.09 &lt;BR /&gt;
Mortgage Low 2011-02-28 4.29 &lt;BR /&gt;
Mortgage Low 2011-03-01 4.19 &lt;BR /&gt;
Mortgage Low 2011-03-02 4.09 &lt;BR /&gt;
Mortgage Low 2011-03-03 4.99 &lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table min_rate as&lt;BR /&gt;
 select a.*,min(b.rate) as min_rate&lt;BR /&gt;
  from temp as a,temp as b&lt;BR /&gt;
   where a.product = b.product and a.treatment = b.treatment&lt;BR /&gt;
         and b.date between a.date-1 and a.date &lt;BR /&gt;
     group by a.product,a.treatment,a.date,a.rate&lt;BR /&gt;
   ;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 13 Apr 2011 03:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-determine-min-rate-in-the-past-36-days/m-p/49006#M13276</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-13T03:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL determine min rate in the past 36 days</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-determine-min-rate-in-the-past-36-days/m-p/49007#M13277</link>
      <description>Thanks a lot ... I couldn't see the forest for the trees ... LOL</description>
      <pubDate>Wed, 13 Apr 2011 12:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-determine-min-rate-in-the-past-36-days/m-p/49007#M13277</guid>
      <dc:creator>wildhogs</dc:creator>
      <dc:date>2011-04-13T12:15:49Z</dc:date>
    </item>
  </channel>
</rss>

