<?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: Minimum values by reporting date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Minimum-values-by-reporting-date/m-p/434098#M107717</link>
    <description>&lt;P&gt;Many answers here....and here's another one &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt; set have;&lt;BR /&gt; length month 8;&lt;BR /&gt; retain lowest_rental_value;&lt;BR /&gt; month = put(received_date, yymmn6.);&lt;BR /&gt; if _n_ = 1 then lowest_rental_value = 100000000;&lt;BR /&gt; if rental_value &amp;lt; lowest_rental_value then lowest_rental_value = rental_value;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt; create table want as &lt;BR /&gt; select account_id, month, min(lowest_rental_value) as lowest_rental_value&lt;BR /&gt; from want&lt;BR /&gt; group by 1,2&lt;BR /&gt; ;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;//Fredrik&lt;/P&gt;</description>
    <pubDate>Mon, 05 Feb 2018 09:14:21 GMT</pubDate>
    <dc:creator>FredrikE</dc:creator>
    <dc:date>2018-02-05T09:14:21Z</dc:date>
    <item>
      <title>Minimum values by reporting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Minimum-values-by-reporting-date/m-p/434090#M107712</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following dataset containing rental values for&amp;nbsp;property valuations&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input Account_Id$ received_date rental_value;
	informat received_date date9.;
	format received_date date9.;
	cards;
	12345 25JAN2008 500
	12345 30JUN2008 600
	12345 12DEC2008 400
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I need is to create another Monthly dataset with the minimum rental value for instance&lt;/P&gt;&lt;P&gt;&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;Account_ID&lt;/TD&gt;&lt;TD&gt;Reporting_Date&lt;/TD&gt;&lt;TD&gt;Rental_value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;Jan-08&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;Feb-08&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;Mar-08&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;Apr-08&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;May-08&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;Jun-08&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;Jul-08&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;Aug-08&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;Sep-08&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;Oct-08&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;Nov-08&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;Dec-08&lt;/TD&gt;&lt;TD&gt;400&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;Jan-09&lt;/TD&gt;&lt;TD&gt;400&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Adnan&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 08:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Minimum-values-by-reporting-date/m-p/434090#M107712</guid>
      <dc:creator>Adnan_Razaq</dc:creator>
      <dc:date>2018-02-05T08:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: Minimum values by reporting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Minimum-values-by-reporting-date/m-p/434091#M107713</link>
      <description>&lt;P&gt;The basic approach could be to create a 2nd table with just month end dates and then to join this table with your Have table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will have to specify a bit more how your actual data could look like, i.e.&lt;/P&gt;
&lt;P&gt;- Could there be more than one record per account_id and received_date?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if yes: which date to chose for the month&lt;/P&gt;
&lt;P&gt;- Why does in your sample&amp;nbsp;result table the record with Reporting_Date Jun-08 have a Rental_Value of 500 and not of 600?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 08:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Minimum-values-by-reporting-date/m-p/434091#M107713</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-02-05T08:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Minimum values by reporting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Minimum-values-by-reporting-date/m-p/434092#M107714</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There can be multiple records for account_id and received date. In those instances I would require to report&amp;nbsp;the minimum rental valu.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will need to report the minimum rental even though we receive a greater rental value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 08:47:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Minimum-values-by-reporting-date/m-p/434092#M107714</guid>
      <dc:creator>Adnan_Razaq</dc:creator>
      <dc:date>2018-02-05T08:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Minimum values by reporting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Minimum-values-by-reporting-date/m-p/434093#M107715</link>
      <description>&lt;P&gt;Use retain, the lag() function, by-group processing, the min() function, and a do loop, making use of the intnx() function for dates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input Account_Id$ received_date rental_value;
	informat received_date date9.;
	format received_date date9.;
	cards;
	12345 25JAN2008 500
	12345 30JUN2008 600
	12345 12DEC2008 400
	;
run;

data want;
set have (rename=(rental_value=_rental_value));
by account_id;
format reporting_date monyy7.;
retain rental_value;
lagdat = lag(received_date);
if first.account_id
then do;
  rental_value = _rental_value;
  reporting_date = intnx('month',received_date,0,'b');
  output;
end;
else do;
  reporting_date = intnx('month',lagdat,1,'b');
  do while (reporting_date &amp;lt; intnx('month',received_date,0,'b'));
    output;
    reporting_date = intnx('month',reporting_date,1,'b');
  end;
  reporting_date = intnx('month',received_date,0,'b');
  rental_value = min(rental_value,_rental_value);
  output;
end;
if last.account_id
then do;
  reporting_date = intnx('month',received_date,1,'b');
  output;
end;
drop
  received_date
  lagdat
  _rental_value
;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Account_    reporting_    rental_
   Id          date        value

 	12345      JAN2008        500  
 	12345      FEB2008        500  
 	12345      MAR2008        500  
 	12345      APR2008        500  
 	12345      MAY2008        500  
 	12345      JUN2008        500  
 	12345      JUL2008        500  
 	12345      AUG2008        500  
 	12345      SEP2008        500  
 	12345      OCT2008        500  
 	12345      NOV2008        500  
 	12345      DEC2008        400  
 	12345      JAN2009        400  
&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Feb 2018 09:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Minimum-values-by-reporting-date/m-p/434093#M107715</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-05T09:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Minimum values by reporting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Minimum-values-by-reporting-date/m-p/434096#M107716</link>
      <description>&lt;P&gt;Use a retain and do loop.&amp;nbsp; However what I can't tell from your post is how far forward you want to go, your example want shows jan09, but this is indicated nowhere in the data?&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  retain lstdt;
  if _n_=1 then lstdt=received_date;
  else do;
    do i=0 to intck('month',lstdt,recieved_date);&lt;BR /&gt;      new_date=intnx('month',lstdt,i);
      output;
    end;
    lstdt=recieved_date;
  end;
  format new_date date9.;
run;&lt;/PRE&gt;
&lt;P&gt;This will create outputs of rows for each month between last row and current.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 09:06:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Minimum-values-by-reporting-date/m-p/434096#M107716</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-05T09:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: Minimum values by reporting date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Minimum-values-by-reporting-date/m-p/434098#M107717</link>
      <description>&lt;P&gt;Many answers here....and here's another one &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt; set have;&lt;BR /&gt; length month 8;&lt;BR /&gt; retain lowest_rental_value;&lt;BR /&gt; month = put(received_date, yymmn6.);&lt;BR /&gt; if _n_ = 1 then lowest_rental_value = 100000000;&lt;BR /&gt; if rental_value &amp;lt; lowest_rental_value then lowest_rental_value = rental_value;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt; create table want as &lt;BR /&gt; select account_id, month, min(lowest_rental_value) as lowest_rental_value&lt;BR /&gt; from want&lt;BR /&gt; group by 1,2&lt;BR /&gt; ;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;//Fredrik&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 09:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Minimum-values-by-reporting-date/m-p/434098#M107717</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2018-02-05T09:14:21Z</dc:date>
    </item>
  </channel>
</rss>

