<?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 Find max of hourly data for each month and what date and time the max occured in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-max-of-hourly-data-for-each-month-and-what-date-and-time/m-p/502926#M134310</link>
    <description>&lt;P&gt;How do I find the max of hourly data by month and keep the date and hour that the max values occurred?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc timeseries data=avg_weighted_kw_class out=max_energy_class;
	var class;
	id date interval=month accumulate=maximum;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Current output looks like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Class&lt;BR /&gt;JAN2018&amp;nbsp; &amp;nbsp; 7.6829856445&lt;BR /&gt;FEB2018&amp;nbsp; &amp;nbsp; 7.4240397874&lt;BR /&gt;MAR2018&amp;nbsp; &amp;nbsp;8.6926150969&lt;BR /&gt;APR2018&amp;nbsp; &amp;nbsp;11.188461168&lt;BR /&gt;MAY2018&amp;nbsp; &amp;nbsp;12.989846577&lt;BR /&gt;JUN2018&amp;nbsp; &amp;nbsp; 14.024950332&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired output:&lt;/P&gt;&lt;P&gt;HOUR&amp;nbsp; &amp;nbsp; DATE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CLASS&lt;/P&gt;&lt;P&gt;14:00&amp;nbsp; &amp;nbsp; &amp;nbsp;3-Jan-18&amp;nbsp; &amp;nbsp; 7.682985645&lt;/P&gt;&lt;P&gt;17:00&amp;nbsp; &amp;nbsp; &amp;nbsp;9-Feb-18&amp;nbsp; &amp;nbsp; 7.424039787&lt;/P&gt;&lt;P&gt;16:00&amp;nbsp; &amp;nbsp; 23-Mar-18&amp;nbsp; &amp;nbsp;8.692615097&lt;/P&gt;&lt;P&gt;16:00&amp;nbsp; &amp;nbsp; 24-Apr-18&amp;nbsp; &amp;nbsp;11.18846117&lt;/P&gt;&lt;P&gt;15:00&amp;nbsp; &amp;nbsp;31-May-18&amp;nbsp; &amp;nbsp;12.98984658&lt;/P&gt;&lt;P&gt;14:00&amp;nbsp; &amp;nbsp; 26-Jun-18&amp;nbsp; &amp;nbsp; 14.02495033&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Oct 2018 14:09:11 GMT</pubDate>
    <dc:creator>KALLEN</dc:creator>
    <dc:date>2018-10-10T14:09:11Z</dc:date>
    <item>
      <title>Find max of hourly data for each month and what date and time the max occured</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-max-of-hourly-data-for-each-month-and-what-date-and-time/m-p/502926#M134310</link>
      <description>&lt;P&gt;How do I find the max of hourly data by month and keep the date and hour that the max values occurred?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc timeseries data=avg_weighted_kw_class out=max_energy_class;
	var class;
	id date interval=month accumulate=maximum;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Current output looks like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Class&lt;BR /&gt;JAN2018&amp;nbsp; &amp;nbsp; 7.6829856445&lt;BR /&gt;FEB2018&amp;nbsp; &amp;nbsp; 7.4240397874&lt;BR /&gt;MAR2018&amp;nbsp; &amp;nbsp;8.6926150969&lt;BR /&gt;APR2018&amp;nbsp; &amp;nbsp;11.188461168&lt;BR /&gt;MAY2018&amp;nbsp; &amp;nbsp;12.989846577&lt;BR /&gt;JUN2018&amp;nbsp; &amp;nbsp; 14.024950332&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired output:&lt;/P&gt;&lt;P&gt;HOUR&amp;nbsp; &amp;nbsp; DATE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CLASS&lt;/P&gt;&lt;P&gt;14:00&amp;nbsp; &amp;nbsp; &amp;nbsp;3-Jan-18&amp;nbsp; &amp;nbsp; 7.682985645&lt;/P&gt;&lt;P&gt;17:00&amp;nbsp; &amp;nbsp; &amp;nbsp;9-Feb-18&amp;nbsp; &amp;nbsp; 7.424039787&lt;/P&gt;&lt;P&gt;16:00&amp;nbsp; &amp;nbsp; 23-Mar-18&amp;nbsp; &amp;nbsp;8.692615097&lt;/P&gt;&lt;P&gt;16:00&amp;nbsp; &amp;nbsp; 24-Apr-18&amp;nbsp; &amp;nbsp;11.18846117&lt;/P&gt;&lt;P&gt;15:00&amp;nbsp; &amp;nbsp;31-May-18&amp;nbsp; &amp;nbsp;12.98984658&lt;/P&gt;&lt;P&gt;14:00&amp;nbsp; &amp;nbsp; 26-Jun-18&amp;nbsp; &amp;nbsp; 14.02495033&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 14:09:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-max-of-hourly-data-for-each-month-and-what-date-and-time/m-p/502926#M134310</guid>
      <dc:creator>KALLEN</dc:creator>
      <dc:date>2018-10-10T14:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: Find max of hourly data for each month and what date and time the max occured</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-max-of-hourly-data-for-each-month-and-what-date-and-time/m-p/502936#M134313</link>
      <description>&lt;P&gt;I don't think proc timeseries is a good tool to get the data and hour corresponding to the maximum monthly class value. This DATA step is probably the best option:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep=date hour maxclass);
  set have (keep=date class) end=end_of_have;

  if dif(month(date)) or end_of_have then do;
    if ptr^=. then do;
      set have (keep=date hour class rename=(class=maxclass)) point=ptr;
      output; 
    end;
    call missing(maxclass,ptr);
  end;

  if class&amp;gt;maxclass then do;
    maxclass=class;
    ptr=_n_;
  end;
run;
   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This program assumes at least one incoming observation per month.&amp;nbsp; The technique here is to keep track of the maxclass value and the observation number (ptr) from which it arises. So at the beginning of the next month (or at end of data) just reread the specified record and output it.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 23:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-max-of-hourly-data-for-each-month-and-what-date-and-time/m-p/502936#M134313</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-10-09T23:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Find max of hourly data for each month and what date and time the max occured</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-max-of-hourly-data-for-each-month-and-what-date-and-time/m-p/502971#M134336</link>
      <description>&lt;P&gt;With SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table max_energy_class as
select
    intnx("month", date, 0) as month format=mmyyd7.,
    date,
    hour,
    class
from avg_weighted_kw_class 
group by calculated month
having class = max(class);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Oct 2018 04:06:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-max-of-hourly-data-for-each-month-and-what-date-and-time/m-p/502971#M134336</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-10-10T04:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Find max of hourly data for each month and what date and time the max occured</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-max-of-hourly-data-for-each-month-and-what-date-and-time/m-p/503093#M134384</link>
      <description>Thank you for your solution. Although I am still learning SQL, I appreciated the efficiency of PGStats' answer.</description>
      <pubDate>Wed, 10 Oct 2018 14:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-max-of-hourly-data-for-each-month-and-what-date-and-time/m-p/503093#M134384</guid>
      <dc:creator>KALLEN</dc:creator>
      <dc:date>2018-10-10T14:10:18Z</dc:date>
    </item>
  </channel>
</rss>

