<?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 value for a day of month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354372#M82903</link>
    <description>&lt;P&gt;This is why it is a good idea to post a) test data in the form of a datastep, and b) what your output should look like. &amp;nbsp;I am just guessing each time:&lt;/P&gt;
&lt;PRE&gt;data inter (keep=yrmon day tot);
  set sashelp.snacks;
  yrmon=catx('-',put(year(date),4.),put(month(date),z2.));
  day=day(date);
  tot=qtysold * price;
run;

proc sort data=inter out=want;
  by yrmon tot day;
run;

data want;
  set want;
  by yrmon;
  if first.yrmon then output;
run;&lt;/PRE&gt;</description>
    <pubDate>Fri, 28 Apr 2017 09:27:53 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-04-28T09:27:53Z</dc:date>
    <item>
      <title>MAX value for a day of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354363#M82897</link>
      <description>&lt;P&gt;Hey.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a task, which I can't really solve. It's about&amp;nbsp;snacks from "sashelp.snacks".&lt;/P&gt;&lt;P&gt;I have to make a table where I could only find the max values of each months. So basically I would see a monthname, the income&amp;nbsp;(max from the month) and the day, which had the max income.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is like:&lt;/P&gt;&lt;PRE&gt;data test.day;
set test.sorted_snack (keep=Day ID);
run;


proc means data=test.sorted_snack max noprint;
class Month;
var Income;
output out=test.inc;
run;&lt;/PRE&gt;&lt;P&gt;and after that I would merge the two by ID. So I would see the Day, Max inc by Month. But it doesn't work...&lt;/P&gt;&lt;P&gt;Can someone help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;p.s.: I can only use datasteps.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 08:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354363#M82897</guid>
      <dc:creator>Derdavos</dc:creator>
      <dc:date>2017-04-28T08:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: MAX value for a day of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354367#M82898</link>
      <description>&lt;P&gt;When you are reffering to the income in sashelp.snacks, do you mean the quantity sold or the quantity multiplied by the retail price of the product?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 09:04:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354367#M82898</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-04-28T09:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: MAX value for a day of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354368#M82899</link>
      <description>&lt;P&gt;You don't need means, just get your data items correctly assigned, then sort them so max is first, then output that row:&lt;/P&gt;
&lt;PRE&gt;data inter (keep=mon day tot);
  set sashelp.snacks;
  mon=month(date);
  day=day(date);
  tot=qtysold * price;
run;

proc sort data=inter out=want;
  by mon tot day;
run;

data want;
  set want;
  by mon;
  if first.mon then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2017 09:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354368#M82899</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-28T09:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: MAX value for a day of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354369#M82900</link>
      <description>&lt;P&gt;I made a new column (income) by multiplying the "quantity sold" with "unit price".&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 09:14:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354369#M82900</guid>
      <dc:creator>Derdavos</dc:creator>
      <dc:date>2017-04-28T09:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: MAX value for a day of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354371#M82902</link>
      <description>&lt;P&gt;It's just write out the max by month. But I have 3 years. So I have to distribute the months like e.g. 2011-11, 2012-11, 2013-11.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 09:25:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354371#M82902</guid>
      <dc:creator>Derdavos</dc:creator>
      <dc:date>2017-04-28T09:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: MAX value for a day of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354372#M82903</link>
      <description>&lt;P&gt;This is why it is a good idea to post a) test data in the form of a datastep, and b) what your output should look like. &amp;nbsp;I am just guessing each time:&lt;/P&gt;
&lt;PRE&gt;data inter (keep=yrmon day tot);
  set sashelp.snacks;
  yrmon=catx('-',put(year(date),4.),put(month(date),z2.));
  day=day(date);
  tot=qtysold * price;
run;

proc sort data=inter out=want;
  by yrmon tot day;
run;

data want;
  set want;
  by yrmon;
  if first.yrmon then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2017 09:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354372#M82903</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-28T09:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: MAX value for a day of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354374#M82905</link>
      <description>&lt;P&gt;I don't know if that is the easiest solution, but I figured it out. Or at leats I have found a solution, which seems to work fine. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here it is:&lt;/P&gt;&lt;PRE&gt;data test.inter (keep= year mon day income);
  set test.sorted_snack;
  day=day(date);
  year=year(date);
  mon=put(date, MONNAME.);
run;

proc sort data=test.inter out=test.want;
  by year mon income day;
run;

data test.want;
  set test.want;
  by year mon;
  if last.mon then output;
  drop year;
run;

proc sort data=test.want out=test.want;
by mon;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2017 09:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354374#M82905</guid>
      <dc:creator>Derdavos</dc:creator>
      <dc:date>2017-04-28T09:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: MAX value for a day of month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354521#M82941</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/135149"&gt;@Derdavos&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I don't know if that is the easiest solution, but I figured it out. Or at leats I have found a solution, which seems to work fine. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Here it is:&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It would help to show exactly what you did first with the SASHelp.snacks data set as we can't duplicate your code without that information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this may be similar to your request.&lt;/P&gt;
&lt;PRE&gt;Data have;
   set sashelp.snacks;
   income =  QtySold*price;
   iddate=date;
   format iddate mmddyy10.;
run;

proc summary data=have nway;
   class date;
   format date yymmd7.;
   var income;
   id iddate;
   output out=want max= maxid(income(iddate))=HighestIncome ;
run;

&lt;/PRE&gt;
&lt;P&gt;If you have an identification variable then proc means/ summary will can find the max and the value of that ID variable associated with the max (or min) or top 3 and such. The format applied to the base Date variable will tell the procedure to group data by the formatted values (month and year in this case) for the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 16:07:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAX-value-for-a-day-of-month/m-p/354521#M82941</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-28T16:07:12Z</dc:date>
    </item>
  </channel>
</rss>

