<?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: Max function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11972#M1206</link>
    <description>Proc sql;&lt;BR /&gt;
select max(var) from ...</description>
    <pubDate>Thu, 26 Mar 2009 13:40:39 GMT</pubDate>
    <dc:creator>Flip</dc:creator>
    <dc:date>2009-03-26T13:40:39Z</dc:date>
    <item>
      <title>Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11971#M1205</link>
      <description>Hi all,&lt;BR /&gt;
&lt;BR /&gt;
Is there a way to take the MAX of a single variable? If not, any suggestions for finding a maximum value in a column(variable)?</description>
      <pubDate>Thu, 26 Mar 2009 13:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11971#M1205</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2009-03-26T13:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11972#M1206</link>
      <description>Proc sql;&lt;BR /&gt;
select max(var) from ...</description>
      <pubDate>Thu, 26 Mar 2009 13:40:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11972#M1206</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-26T13:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11973#M1207</link>
      <description>I need some serious help. Is there any way I can post an example of a data set to ask questions about?</description>
      <pubDate>Thu, 26 Mar 2009 13:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11973#M1207</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2009-03-26T13:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11974#M1208</link>
      <description>So, I'll do my best to explain. &lt;BR /&gt;
&lt;BR /&gt;
I have a .csv dataset which I import into SAS. This dataset which we'll call usage, contains account numbers and names in a row. Across from the account number and name there is a date ie 01/01/2008 and then there is hour1 - hour24 which contain electricity usage values. Each account number has 366 rows (leap year) one for each day of the year. Each row contains the account number, customer name, date, hour1-hour24.    I need to find the max of hour1-hour24 by MONTH. IE there is one peak value in the 744 hours in January. I need to return that value. Then move on to February and so on.........There are about 150 customers in this data set which equals about 55000 rows. Help PLEASE!</description>
      <pubDate>Thu, 26 Mar 2009 13:52:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11974#M1208</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2009-03-26T13:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11975#M1209</link>
      <description>Something kind of like this should do it.&lt;BR /&gt;
&lt;BR /&gt;
data usagesum;&lt;BR /&gt;
set usage end = eof;&lt;BR /&gt;
retain maxuse ; &lt;BR /&gt;
  &lt;BR /&gt;
if (day(date) = 1 or eof) and not (_n_ = 1) then do;&lt;BR /&gt;
   month = month(lag(date));&lt;BR /&gt;
   output;&lt;BR /&gt;
   maxuse = 0;&lt;BR /&gt;
end;&lt;BR /&gt;
maxuse = max(maxuse , max(h1 - h24));&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 26 Mar 2009 14:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11975#M1209</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-26T14:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11976#M1210</link>
      <description>Very confusing. Can you clarify a little bit? Keep in mind my SAS knowledge isn't nearly what yours is.</description>
      <pubDate>Thu, 26 Mar 2009 14:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11976#M1210</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2009-03-26T14:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11977#M1211</link>
      <description>Actually, I think I have that part. Thank you very much.&lt;BR /&gt;
&lt;BR /&gt;
How would you recommend I output the account number, month, and maxuse value into something like an Excel file?</description>
      <pubDate>Thu, 26 Mar 2009 14:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11977#M1211</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2009-03-26T14:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11978#M1212</link>
      <description>data usagesum;&lt;BR /&gt;
set usage end = eof; &lt;BR /&gt;
retain maxuse ; * keep the maxuse from obs to obs;&lt;BR /&gt;
by cust date;&lt;BR /&gt;
if (day(date) = 1 or last.cust) and not (_n_ = 1) then do;  * Do this stuf on the 1st day of month or the last reord for a customer;&lt;BR /&gt;
month = month(lag(date)); * since we do this on the first of the next month use last month Well you won't want to do this on the last customer record;&lt;BR /&gt;
output; &lt;BR /&gt;
maxuse = 0;&lt;BR /&gt;
end;&lt;BR /&gt;
maxuse = max(maxuse , max(h1 - h24));  *maximum of retained value and the max of the hourly readings;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
This is just a starting point for you, but you should be able to build it from there.</description>
      <pubDate>Thu, 26 Mar 2009 14:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11978#M1212</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-26T14:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11979#M1213</link>
      <description>Ok,&lt;BR /&gt;
&lt;BR /&gt;
Now I have to add on another part. I need to find the peak usage values for every month like before, but this time I need to find one peak for the hours of 12 pm to 8 pm and I need to find another peak for all other hours not in between 12 and 8. This is still a monthly peak it just needs to be broken up by hours now. Any suggestions?</description>
      <pubDate>Thu, 26 Mar 2009 15:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11979#M1213</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2009-03-26T15:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11980#M1214</link>
      <description>I don't know about the others but personally I learned what I know by sitting back, thinking about things, reading books, trying different things and asking questions when I was really stuck.&lt;BR /&gt;
&lt;BR /&gt;
I honestly don't believe you cannot figure this answer out for yourself. &lt;BR /&gt;
&lt;BR /&gt;
I don't mean to be harsh but I'm just saying that getting all the answers form someone else is not going to teach you very much.&lt;BR /&gt;
&lt;BR /&gt;
If you really really can't figure it out then come back and I can point it out.&lt;BR /&gt;
&lt;BR /&gt;
By no means do I mean don't ask questions but if the answers are already there and you just need to apply a little bit of work then you're not going to get much out of it by asking for every solution.</description>
      <pubDate>Thu, 26 Mar 2009 15:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11980#M1214</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-26T15:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11981#M1215</link>
      <description>If I new the solution I wouldn't be asking............</description>
      <pubDate>Thu, 26 Mar 2009 15:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11981#M1215</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2009-03-26T15:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11982#M1216</link>
      <description>Nor would I be asking if I didn't have to have something done in a short period of time which sort of hampers the whole learning thing.</description>
      <pubDate>Thu, 26 Mar 2009 15:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11982#M1216</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2009-03-26T15:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11983#M1217</link>
      <description>Fair enough, try this.......&lt;BR /&gt;
&lt;BR /&gt;
data usagesum;&lt;BR /&gt;
set usage end = eof; &lt;BR /&gt;
retain maxuse maxuse12_8 maxuse_other ; * keep the maxuse from obs to obs;&lt;BR /&gt;
by cust date;&lt;BR /&gt;
if (day(date) = 1 or last.cust) and not (_n_ = 1) then do; * Do this stuf on the 1st day of month or the last reord for a customer;&lt;BR /&gt;
month = month(lag(date)); * since we do this on the first of the next month use last month Well you won't want to do this on the last customer record;&lt;BR /&gt;
output; &lt;BR /&gt;
maxuse = 0;&lt;BR /&gt;
maxuse12_8=0;&lt;BR /&gt;
maxuse_other=0;&lt;BR /&gt;
end;&lt;BR /&gt;
maxuse = max(maxuse , max(h1 - h24)); *maximum of retained value and the max of the hourly readings;&lt;BR /&gt;
maxuse12_8 = max(maxuse12_8 , max(h12 - h20)); *maximum of retained value and the max of the hourly readings;&lt;BR /&gt;
maxuse_other = max(maxuse_other , max(max(h1 - h11),max(h21-h24)); *maximum of retained value and the max of the hourly readings;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: pznew

Message was edited by: pznew</description>
      <pubDate>Thu, 26 Mar 2009 16:12:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11983#M1217</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-26T16:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11984#M1218</link>
      <description>If you're going to be doing this sort of stuff regularly, have a look at proc means.&lt;BR /&gt;
&lt;BR /&gt;
*build a test dataset with random usage amounts;&lt;BR /&gt;
data usage;&lt;BR /&gt;
*format the date;&lt;BR /&gt;
format date date9.;&lt;BR /&gt;
*create 50 accounts;&lt;BR /&gt;
do i=1 to 50;&lt;BR /&gt;
  account=i;&lt;BR /&gt;
  *366 days in the year;&lt;BR /&gt;
  do x=1 to 366;&lt;BR /&gt;
    date='31DEC2007'd + x;&lt;BR /&gt;
    array h(24);&lt;BR /&gt;
    *24 hours of random usage variables;&lt;BR /&gt;
    do s=1 to 24;&lt;BR /&gt;
      h(s)=round(ranuni(today())*100,0.01);&lt;BR /&gt;
    end;&lt;BR /&gt;
    *output and observation for each date;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*set up the data for the proc means;&lt;BR /&gt;
data months;&lt;BR /&gt;
set usage;&lt;BR /&gt;
*create the maximums for each day;&lt;BR /&gt;
max_24=max(of h1-h24);&lt;BR /&gt;
max_12_8=max(of h12-h20);&lt;BR /&gt;
max_other=max(max(of h1-h11),max(of h21-h24));&lt;BR /&gt;
*create a variable holding the month;&lt;BR /&gt;
month=month(date);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*proc means;&lt;BR /&gt;
proc means data=months noprint nway;&lt;BR /&gt;
by account month;&lt;BR /&gt;
var max_24 max_12_8 max_other;&lt;BR /&gt;
output out=max_usage(drop=_type_ _freq_) max=/autoname;&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 26 Mar 2009 16:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11984#M1218</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-26T16:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11985#M1219</link>
      <description>I tend to agree with feedback posted - it would be more reasonable to see a post with a SAS coding problem, given a particular data-manipulation, calculation or info-output challenge, considering that time is part of the SAS application development process (to include time set aside for learning and as much self-initiated debugging).  To continue on one thread topic with multiple questions, after engaging someone's response, detracts from the purpose of the original post.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 26 Mar 2009 16:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11985#M1219</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-26T16:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11986#M1220</link>
      <description>data kva;&lt;BR /&gt;
infile 'C:\Documents and Settings\dubauaw\Desktop\Jims KVA 2009\Rate 56 (Group 1)Cal.csv' dsd missover LRECL=1000000;&lt;BR /&gt;
length account $9. meter $9. channel $12. LRID $15. name $25. meteragain $9.;&lt;BR /&gt;
input account $ meter $ regtype $ channel $ LRID $ name $ meteragain $ type1 $ type2 $ date hour1-hour24;&lt;BR /&gt;
informat date mmddyy9.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data usagesum;&lt;BR /&gt;
set kva end = eof; &lt;BR /&gt;
retain maxuse maxuse12_8 maxuse_other max_offpeak ; &lt;BR /&gt;
if (day(date) = 1 or last.account) and not (_n_ = 1) then do; &lt;BR /&gt;
month = month(lag(date)); &lt;BR /&gt;
output; &lt;BR /&gt;
maxuse = 0;&lt;BR /&gt;
maxuse12_8=0;&lt;BR /&gt;
maxuse_other=0;&lt;BR /&gt;
max_offpeak =0;&lt;BR /&gt;
end;&lt;BR /&gt;
maxuse = max(maxuse , max(of hour1 - hour24)); &lt;BR /&gt;
maxuse12_8 = max(maxuse12_8 , max(of hour12 - hour20)); &lt;BR /&gt;
maxuse_other = max(of maxuse_other , max(max(of hour1 - hour11),max(of hour21-hour24)));&lt;BR /&gt;
if weekday(date) NE 2-6 then do; &lt;BR /&gt;
max_offpeak = max(of maxuse_other, max(of hour1-hour24));&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
There is my code. My only problem now is the first account is missing a month. The month variable works like it should but the first account skips a month. Not sure why? That is to say that the month variable works all the way through, but something isn't lining up.

Message was edited by: Aar684</description>
      <pubDate>Fri, 27 Mar 2009 12:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11986#M1220</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2009-03-27T12:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11987#M1221</link>
      <description>What is the month variable for?</description>
      <pubDate>Fri, 27 Mar 2009 13:32:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11987#M1221</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-27T13:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11988#M1222</link>
      <description>just to keep track of the month I believe.&lt;BR /&gt;
&lt;BR /&gt;
my problem is the first account only does 11 months of peaks where as the rest of the data set/accounts have all 12, any ideas?</description>
      <pubDate>Fri, 27 Mar 2009 13:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11988#M1222</guid>
      <dc:creator>Aar684</dc:creator>
      <dc:date>2009-03-27T13:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11989#M1223</link>
      <description>if _n_ = 1 then month = month(date);</description>
      <pubDate>Fri, 27 Mar 2009 14:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11989#M1223</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-27T14:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: Max function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11990#M1224</link>
      <description>Have you heard of the software development lifecycle? &lt;BR /&gt;
&lt;BR /&gt;
Basically it teaches us that the most important thing is to get the requirements right from the start. This is a case in point. Because you asked for something at the start and then changed your requirements the program is becoming a mess. &lt;BR /&gt;
&lt;BR /&gt;
If you fix that then other things go wrong and it just takes a whole lot of messing around. I'll try:&lt;BR /&gt;
&lt;BR /&gt;
data usagesum;&lt;BR /&gt;
set kva end = eof; &lt;BR /&gt;
retain maxuse maxuse12_8 maxuse_other max_offpeak; &lt;BR /&gt;
month = month(date); &lt;BR /&gt;
*if its the first of the month of the first observation for the account;&lt;BR /&gt;
*set all the reained varaibles to zero, to start again;&lt;BR /&gt;
if (day(date) = 1 or first.account) then do; &lt;BR /&gt;
maxuse = 0;&lt;BR /&gt;
maxuse12_8=0;&lt;BR /&gt;
maxuse_other=0;&lt;BR /&gt;
max_offpeak =0;&lt;BR /&gt;
end;&lt;BR /&gt;
maxuse = max(maxuse , max(of hour1 - hour24)); &lt;BR /&gt;
maxuse12_8 = max(maxuse12_8 , max(of hour12 - hour20)); &lt;BR /&gt;
maxuse_other = max(of maxuse_other , max(max(of hour1 - hour11),max(of hour21-hour24)));&lt;BR /&gt;
if weekday(date) NE 2-6 then do; &lt;BR /&gt;
max_offpeak = max(of maxuse_other, max(of hour1-hour24));&lt;BR /&gt;
end;&lt;BR /&gt;
*if it is the last record for the account or the last day of the month;&lt;BR /&gt;
*output the observation;&lt;BR /&gt;
if last.account or month ne month(date+1) then output;&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 27 Mar 2009 14:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Max-function/m-p/11990#M1224</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-27T14:06:45Z</dc:date>
    </item>
  </channel>
</rss>

