<?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: How do I order a dataset by a monyy7. formated value in sequential order? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-order-a-dataset-by-a-monyy7-formated-value-in/m-p/934312#M367404</link>
    <description>&lt;P&gt;Don't use PUT, just use the formatted numeric value. For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
	format date mmddyy10. value dollar10.;
	do Date='01JAN2024'd to '10JUL2024'd by 7;
		value+month(date);
		output;
	end;
run;
		 
proc means data=have sum maxdec=2;
	class date;
	format date monyy7.;
	var value;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Means: Summary statistics" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt; &lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c b header" colspan="3" scope="colgroup"&gt;Analysis Variable : value&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;date&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;N Obs&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Sum&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;JAN24&lt;/TH&gt;
&lt;TH class="r t data"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;15.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;FEB24&lt;/TH&gt;
&lt;TH class="r t data"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;40.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;MAR24&lt;/TH&gt;
&lt;TH class="r t data"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;82.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;APR24&lt;/TH&gt;
&lt;TH class="r t data"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;185.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;MAY24&lt;/TH&gt;
&lt;TH class="r t data"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;230.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;JUN24&lt;/TH&gt;
&lt;TH class="r t data"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;320.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;JUL24&lt;/TH&gt;
&lt;TH class="r t data"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;199.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Mon, 01 Jul 2024 18:10:14 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2024-07-01T18:10:14Z</dc:date>
    <item>
      <title>How do I order a dataset by a monyy7. formated value in sequential order?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-order-a-dataset-by-a-monyy7-formated-value-in/m-p/934310#M367402</link>
      <description>&lt;P&gt;I have aggregated my data to get averages by Month, where I take a date value and use the put function to format the date in a monthyear format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put(Date, monyy7.) as Month&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want the data set to be grouped by that, AND ordered by that in sequential order.&amp;nbsp; However, since this is a character format it is ordering it in alphabetical order.&amp;nbsp; Is there a numeric equivalent for this, or another way to have my aggregated data in the proper order? I need to have the months spelled out or at least abbreviated as this format does.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried using ORDER BY Date (and leaving it out of the select to get the aggregation), but this gives me duplicates even if I use DISTINCT.&amp;nbsp; I've also tried using 2 steps by creating the month variable in an unaggregated set and ordering by Date, but that order does not carry over when I create an aggregated set from it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 18:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-order-a-dataset-by-a-monyy7-formated-value-in/m-p/934310#M367402</guid>
      <dc:creator>RandoDando</dc:creator>
      <dc:date>2024-07-01T18:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do I order a dataset by a monyy7. formated value in sequential order?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-order-a-dataset-by-a-monyy7-formated-value-in/m-p/934311#M367403</link>
      <description>&lt;P&gt;I found a solution, but I am open to alternatives.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Select distinct
Month */the mmyy7 format*/,
avg(count) as AVG_CNT
from my_data
group by month
ORDER BY year(Date), Month(Date);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Jul 2024 18:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-order-a-dataset-by-a-monyy7-formated-value-in/m-p/934311#M367403</guid>
      <dc:creator>RandoDando</dc:creator>
      <dc:date>2024-07-01T18:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I order a dataset by a monyy7. formated value in sequential order?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-order-a-dataset-by-a-monyy7-formated-value-in/m-p/934312#M367404</link>
      <description>&lt;P&gt;Don't use PUT, just use the formatted numeric value. For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
	format date mmddyy10. value dollar10.;
	do Date='01JAN2024'd to '10JUL2024'd by 7;
		value+month(date);
		output;
	end;
run;
		 
proc means data=have sum maxdec=2;
	class date;
	format date monyy7.;
	var value;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Means: Summary statistics" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt; &lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c b header" colspan="3" scope="colgroup"&gt;Analysis Variable : value&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;date&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;N Obs&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Sum&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;JAN24&lt;/TH&gt;
&lt;TH class="r t data"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;15.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;FEB24&lt;/TH&gt;
&lt;TH class="r t data"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;40.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;MAR24&lt;/TH&gt;
&lt;TH class="r t data"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;82.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;APR24&lt;/TH&gt;
&lt;TH class="r t data"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;185.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;MAY24&lt;/TH&gt;
&lt;TH class="r t data"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;230.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;JUN24&lt;/TH&gt;
&lt;TH class="r t data"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;320.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r t data"&gt;JUL24&lt;/TH&gt;
&lt;TH class="r t data"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;199.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 01 Jul 2024 18:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-order-a-dataset-by-a-monyy7-formated-value-in/m-p/934312#M367404</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-07-01T18:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do I order a dataset by a monyy7. formated value in sequential order?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-order-a-dataset-by-a-monyy7-formated-value-in/m-p/934314#M367405</link>
      <description>&lt;P&gt;You could use the yymm7 format instead of monyy7.&amp;nbsp; With yymm7, the alphabetical sort of the character values is in chronological order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
  select put(date,yymm7.) as month, mean(y) as mean
  from have
  group by month
  order by month
   ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp;, the PROC MEANS approach is even simpler.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 18:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-order-a-dataset-by-a-monyy7-formated-value-in/m-p/934314#M367405</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-07-01T18:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I order a dataset by a monyy7. formated value in sequential order?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-order-a-dataset-by-a-monyy7-formated-value-in/m-p/934339#M367410</link>
      <description>&lt;P&gt;I agree, use PROC MEANS here, and not PROC SQL. Another benefit is that learning PROC MEANS is a very valuable thing to do, and in my opinion, SQL should not be your first choice for computing statistics.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 19:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-order-a-dataset-by-a-monyy7-formated-value-in/m-p/934339#M367410</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-07-01T19:58:42Z</dc:date>
    </item>
  </channel>
</rss>

