<?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: help with max function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60341#M13061</link>
    <description>OK.  You were close.  I think you can actually do this without BY-group processing; my code is not tested.  :&lt;BR /&gt;
&lt;BR /&gt;
PROC SORT DATA=kva; BY account date;  RUN;&lt;BR /&gt;
* assumes dates are SAS dates, not text strings;&lt;BR /&gt;
&lt;BR /&gt;
data usagesum;&lt;BR /&gt;
set kva;  * end = eof;  * end not needed.;&lt;BR /&gt;
retain maxuse;&lt;BR /&gt;
month = month(date);&lt;BR /&gt;
if (day(date) = 1) /*  and not (_n_ = 1) */  then do;  *  RETAINed variables initialized to 0 for _N_=1 already.;&lt;BR /&gt;
maxuse=0;&lt;BR /&gt;
end;&lt;BR /&gt;
maxuse= max(of MAXUSE hour1 - hour24);  * added maxuse to accumulate through the month.;&lt;BR /&gt;
PUT account date maxuse;  * debugging code to see if the accumulatior is working;&lt;BR /&gt;
if  /* last.account or */ month ne month(date+1) then output;  * "last" not needed.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Give this a try and see where you get.&lt;BR /&gt;
&lt;BR /&gt;
Doc&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Doc@Duke

Message was edited by: Doc@Duke</description>
    <pubDate>Fri, 19 Feb 2010 18:17:10 GMT</pubDate>
    <dc:creator>Doc_Duke</dc:creator>
    <dc:date>2010-02-19T18:17:10Z</dc:date>
    <item>
      <title>help with max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60334#M13054</link>
      <description>Hi all,&lt;BR /&gt;
&lt;BR /&gt;
I have a csv dataset that includes an account number, a date, and 24 hours of data per day. Each row contains one day of a month of the year. All account numbers have 365 days. &lt;BR /&gt;
&lt;BR /&gt;
So the sample data set is as follows:&lt;BR /&gt;
&lt;BR /&gt;
account#   date   hour1   hour2   hour3  ...............hour24&lt;BR /&gt;
&lt;BR /&gt;
There are around 50 account numbers in the data set totaling somewhere in the range of 4000 or so rows. I need to find the maximum value by MONTH and return that value for each account number for each month. So, in the end I will have 12 max values for each account number. HELP! PLEASE. The code, minus the import that I have so far is as follows :&lt;BR /&gt;
&lt;BR /&gt;
data usagesum;&lt;BR /&gt;
set kva end = eof; &lt;BR /&gt;
retain maxuse; &lt;BR /&gt;
month = month(date); &lt;BR /&gt;
if (day(date) = 1) and not (_n_ = 1) then do;&lt;BR /&gt;
maxuse=0;&lt;BR /&gt;
end;&lt;BR /&gt;
maxuse= max(of hour1 - hour24); &lt;BR /&gt;
if last.account or month ne month(date+1) then output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I am getting the max but not of the entire month.

Message was edited by: Aar684</description>
      <pubDate>Fri, 19 Feb 2010 16:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60334#M13054</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2010-02-19T16:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: help with max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60335#M13055</link>
      <description>You are using what's called "BY GROUP PROCESSING" -- the FIRST.&lt;VARIABLE&gt; and/or LAST.&lt;VARIABLE&gt;  must also include a BY statement.  So, you will need to derive all variables, sort the data, then have a DATA step with your max-value derivation logic.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Recommended Google advanced search argument, this topic/post:&lt;BR /&gt;
&lt;BR /&gt;
by group processing site:sas.com&lt;/VARIABLE&gt;&lt;/VARIABLE&gt;</description>
      <pubDate>Fri, 19 Feb 2010 16:35:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60335#M13055</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-02-19T16:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: help with max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60336#M13056</link>
      <description>Try changing the third from the last line from&lt;BR /&gt;
maxuse= max(of hour1 - hour24); &lt;BR /&gt;
to&lt;BR /&gt;
maxuse= max(of maxuse hour1 - hour24); &lt;BR /&gt;
.  That should include the max from the previous records in the month.&lt;BR /&gt;
&lt;BR /&gt;
Doc Muhlbaier&lt;BR /&gt;
Duke

[This is in addition to Scott's comments.]&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Doc@Duke</description>
      <pubDate>Fri, 19 Feb 2010 16:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60336#M13056</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2010-02-19T16:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: help with max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60337#M13057</link>
      <description>Very confusing. Is my max-value derivation logic even remotely correct?</description>
      <pubDate>Fri, 19 Feb 2010 16:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60337#M13057</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2010-02-19T16:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: help with max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60338#M13058</link>
      <description>Scott, &lt;BR /&gt;
&lt;BR /&gt;
I am sorry. My knowledge is very basic. I was getting help from someone here who isn't available to me at the moment. I am lost, but would like to learn. Unfortunately I have a tight time constraint. Am I any where near where I need to be?</description>
      <pubDate>Fri, 19 Feb 2010 16:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60338#M13058</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2010-02-19T16:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: help with max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60339#M13059</link>
      <description>You are missing the BY ACCOUNT MONTH;&lt;BR /&gt;
statement after the SET statement.</description>
      <pubDate>Fri, 19 Feb 2010 17:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60339#M13059</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-02-19T17:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: help with max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60340#M13060</link>
      <description>Yes, you are close, but your MONTH derivation code must be in a separate DATA step.  You cannot have a SET with a BY where the variable is not yet derived -- that's why you need multiple DATA steps -- suggest adding a SORT as mentioned.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 19 Feb 2010 17:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60340#M13060</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-02-19T17:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: help with max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60341#M13061</link>
      <description>OK.  You were close.  I think you can actually do this without BY-group processing; my code is not tested.  :&lt;BR /&gt;
&lt;BR /&gt;
PROC SORT DATA=kva; BY account date;  RUN;&lt;BR /&gt;
* assumes dates are SAS dates, not text strings;&lt;BR /&gt;
&lt;BR /&gt;
data usagesum;&lt;BR /&gt;
set kva;  * end = eof;  * end not needed.;&lt;BR /&gt;
retain maxuse;&lt;BR /&gt;
month = month(date);&lt;BR /&gt;
if (day(date) = 1) /*  and not (_n_ = 1) */  then do;  *  RETAINed variables initialized to 0 for _N_=1 already.;&lt;BR /&gt;
maxuse=0;&lt;BR /&gt;
end;&lt;BR /&gt;
maxuse= max(of MAXUSE hour1 - hour24);  * added maxuse to accumulate through the month.;&lt;BR /&gt;
PUT account date maxuse;  * debugging code to see if the accumulatior is working;&lt;BR /&gt;
if  /* last.account or */ month ne month(date+1) then output;  * "last" not needed.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Give this a try and see where you get.&lt;BR /&gt;
&lt;BR /&gt;
Doc&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Doc@Duke

Message was edited by: Doc@Duke</description>
      <pubDate>Fri, 19 Feb 2010 18:17:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60341#M13061</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2010-02-19T18:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: help with max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60342#M13062</link>
      <description>Ok guys. Trying your suggestions and will report back. Didn't have a chance to look at this again as I was out sick. I am going to plugging away today. Thanks all.</description>
      <pubDate>Tue, 23 Feb 2010 13:33:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-max-function/m-p/60342#M13062</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2010-02-23T13:33:08Z</dc:date>
    </item>
  </channel>
</rss>

