<?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: Rename dynamic month to char and order desc in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736287#M229338</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&amp;nbsp;wrote:
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I should have posted the proc transpose results.&amp;nbsp; Here it is&lt;/P&gt;
&lt;TABLE width="384"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;section&lt;/TD&gt;
&lt;TD width="64"&gt;_NAME_&lt;/TD&gt;
&lt;TD width="64"&gt;20-Jan&lt;/TD&gt;
&lt;TD width="64"&gt;20-Feb&lt;/TD&gt;
&lt;TD width="64"&gt;20-Mar&lt;/TD&gt;
&lt;TD width="64"&gt;20-Apr&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;central&lt;/TD&gt;
&lt;TD&gt;tot_cnt&lt;/TD&gt;
&lt;TD&gt;22&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan="6"&gt;Desired result is to dynamically name the header(dates)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan="5"&gt;with a character varaible based on the month&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan="3"&gt;descending order. Like this&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;section&lt;/TD&gt;
&lt;TD&gt;_NAME_&lt;/TD&gt;
&lt;TD&gt;Month3&lt;/TD&gt;
&lt;TD&gt;Month2&lt;/TD&gt;
&lt;TD&gt;Month1&lt;/TD&gt;
&lt;TD&gt;Month0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;central&lt;/TD&gt;
&lt;TD&gt;tot_cnt&lt;/TD&gt;
&lt;TD&gt;22&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you have variable in your data with the numbers like 0, 1, 2 you can use that variable as an ID variable and combine that with a PREFIX option in Proc transpose to generate the headings (though suspect with multiple records whether you get the desired one)&lt;/P&gt;
&lt;PRE&gt;proc transpose data=have out=want let
   prefix=month;
   by section;
   var tot_cnt;
   id month_sort;
run;&lt;/PRE&gt;
&lt;P&gt;which duplicates your last version.&lt;/P&gt;
&lt;P&gt;If part of your problem is to get the months then the date I provided above and intck function returns intervals:&lt;/P&gt;
&lt;P&gt;Months_previous = intck('month',dateval, '01APR2020'd);&lt;/P&gt;
&lt;P&gt;form example. I am not going to use TODAY(), which returns the current date and might be used to generate dynamic results as the the values you provided are all apparently in 2020 and the 'months' would be 18 to 12 which does not go along with "4" in any way. You could filter you data to only use the Months_previous in the range you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Not quite sure of your statement regarding formatting &amp;lt;&amp;gt;&amp;nbsp; Are you saying begin the code with &amp;lt;&amp;gt; and end it with &amp;lt;/&amp;gt;&amp;nbsp; as in html??&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No. Above the message window you type in on this forum should be a row of icons. The 7th one looks like &amp;lt;/&amp;gt;. Click on that an you get a text box to paste text into.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Apr 2021 23:17:41 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-04-21T23:17:41Z</dc:date>
    <item>
      <title>Rename dynamic month to char and order desc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736258#M229322</link>
      <description>&lt;P&gt;&lt;FONT face="Courier New" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; section $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;25&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt; month_ $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt; tot_cnt &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt; month_sort &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;8&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; section -- month_sort;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;central JAN20 10 3&lt;/P&gt;
&lt;P&gt;central JAN20 22 3&lt;/P&gt;
&lt;P&gt;central FEB20 30 2&lt;/P&gt;
&lt;P&gt;central FEB20 88 2&lt;/P&gt;
&lt;P&gt;central MAR20 30 1&lt;/P&gt;
&lt;P&gt;central MAR20 88 1&lt;/P&gt;
&lt;P&gt;central APR20 30 0&lt;/P&gt;
&lt;P&gt;central APR20 88 0&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" color="#000080"&gt;transpose&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" color="#0000ff"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;=have &lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;out&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;=want &lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;let&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;id&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; month_;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;var&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; tot_cnt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; section;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#008080"&gt;&lt;STRONG&gt;1.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; The report will always have a &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt; month window (in this case Jan-Apr)&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#008080"&gt;&lt;STRONG&gt;3.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; Each month will increment however we will only have the &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt; month window.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;So next month would be (Feb-May)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#008080"&gt;&lt;STRONG&gt;4.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; Since we are in April the month_sort for this month is &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;0.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt; It increments based on &lt;/FONT&gt;the month elapse&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#008080"&gt;&lt;STRONG&gt;3.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; Is there a way to dynamically rename the month results in proc transpose from&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the numeric date to a character based on the month_sort? (ie Month_3 Month_2 ) and order by&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;the month_sort &lt;/FONT&gt;&lt;FONT face="Courier New" color="#008080"&gt;desc.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 21:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736258#M229322</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-04-21T21:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Rename dynamic month to char and order desc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736262#M229325</link>
      <description>&lt;P&gt;Really need to show what you expect for output.&lt;/P&gt;
&lt;P&gt;Reread your 1 through 4 and consider that we do not know what you actually want to do, there is no "report" included so references to that make no sense. And since we are in APRIL 2021 all of those dates you show are 12 to 16 months ago. &lt;/P&gt;
&lt;P&gt;How is "month elapse" to be used, or "month_sort" no example actually provided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why is the proc transpose included at all?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint: learn to use date values instead of (hard to work with text) like "APR20".&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   length section $25
      month_ $5
      tot_cnt 3
      month_sort 8;
   input section -- month_sort;
   dateval= input('01'||month_,date7.);
   format dateval MONyy.;
datalines;
central JAN20 10 3
central JAN20 22 3
central FEB20 30 2
central FEB20 88 2
central MAR20 30 1
central MAR20 88 1
central APR20 30 0
central APR20 88 0
;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second hint: make sure everyone can tell if the 20 is a day of the month or a year. Not at all obvious.&lt;/P&gt;
&lt;P&gt;Below is an example using a specific date to select 2 dates less than 2 months prior.&lt;/P&gt;
&lt;PRE&gt;proc print data=have;
   where intck('month',dateval,'01APR2020'd) lt 2;
run;&lt;/PRE&gt;
&lt;P&gt;Once you have an actual date then incrementing is easy with a function like like INTNX to set boundaries or INTCK to investigate intervals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint 3: Post code or log entries into text boxes opened on the forum with the &amp;lt;/&amp;gt; icon to maintain formatting and prevent odd characters from creeping into code when the forum software reformats text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 21:32:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736262#M229325</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-21T21:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: Rename dynamic month to char and order desc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736278#M229334</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Really need to show what you expect for output.&lt;/P&gt;
&lt;P&gt;Reread your 1 through 4 and consider that we do not know what you actually want to do, there is no "report" included so references to that make no sense. And since we are in APRIL 2021 all of those dates you show are 12 to 16 months ago.&lt;/P&gt;
&lt;P&gt;How is "month elapse" to be used, or "month_sort" no example actually provided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why is the proc transpose included at all?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint: learn to use date values instead of (hard to work with text) like "APR20".&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   length section $25
      month_ $5
      tot_cnt 3
      month_sort 8;
   input section -- month_sort;
   dateval= input('01'||month_,date7.);
   format dateval MONyy.;
datalines;
central JAN20 10 3
central JAN20 22 3
central FEB20 30 2
central FEB20 88 2
central MAR20 30 1
central MAR20 88 1
central APR20 30 0
central APR20 88 0
;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second hint: make sure everyone can tell if the 20 is a day of the month or a year. Not at all obvious.&lt;/P&gt;
&lt;P&gt;Below is an example using a specific date to select 2 dates less than 2 months prior.&lt;/P&gt;
&lt;PRE&gt;proc print data=have;
   where intck('month',dateval,'01APR2020'd) lt 2;
run;&lt;/PRE&gt;
&lt;P&gt;Once you have an actual date then incrementing is easy with a function like like INTNX to set boundaries or INTCK to investigate intervals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint 3: Post code or log entries into text boxes opened on the forum with the &amp;lt;/&amp;gt; icon to maintain formatting and prevent odd characters from creeping into code when the forum software reformats text.&lt;/P&gt;
&lt;P&gt;I should have posted the proc transpose results.&amp;nbsp; Here it is&lt;/P&gt;
&lt;TABLE width="384"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;section&lt;/TD&gt;
&lt;TD width="64"&gt;_NAME_&lt;/TD&gt;
&lt;TD width="64"&gt;20-Jan&lt;/TD&gt;
&lt;TD width="64"&gt;20-Feb&lt;/TD&gt;
&lt;TD width="64"&gt;20-Mar&lt;/TD&gt;
&lt;TD width="64"&gt;20-Apr&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;central&lt;/TD&gt;
&lt;TD&gt;tot_cnt&lt;/TD&gt;
&lt;TD&gt;22&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan="6"&gt;Desired result is to dynamically name the header(dates)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan="5"&gt;with a character varaible based on the month&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan="3"&gt;descending order. Like this&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;section&lt;/TD&gt;
&lt;TD&gt;_NAME_&lt;/TD&gt;
&lt;TD&gt;Month3&lt;/TD&gt;
&lt;TD&gt;Month2&lt;/TD&gt;
&lt;TD&gt;Month1&lt;/TD&gt;
&lt;TD&gt;Month0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;central&lt;/TD&gt;
&lt;TD&gt;tot_cnt&lt;/TD&gt;
&lt;TD&gt;22&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Not quite sure of your statement regarding formatting &amp;lt;&amp;gt;&amp;nbsp; Are you saying begin the code with &amp;lt;&amp;gt; and end it with &amp;lt;/&amp;gt;&amp;nbsp; as in html??&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 22:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736278#M229334</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-04-21T22:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: Rename dynamic month to char and order desc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736286#M229337</link>
      <description>&lt;P&gt;How did 20-JAN become MONTH3 ?&amp;nbsp; Why not MONTH1 or MONTH235 ?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 23:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736286#M229337</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-21T23:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Rename dynamic month to char and order desc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736287#M229338</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&amp;nbsp;wrote:
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I should have posted the proc transpose results.&amp;nbsp; Here it is&lt;/P&gt;
&lt;TABLE width="384"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;section&lt;/TD&gt;
&lt;TD width="64"&gt;_NAME_&lt;/TD&gt;
&lt;TD width="64"&gt;20-Jan&lt;/TD&gt;
&lt;TD width="64"&gt;20-Feb&lt;/TD&gt;
&lt;TD width="64"&gt;20-Mar&lt;/TD&gt;
&lt;TD width="64"&gt;20-Apr&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;central&lt;/TD&gt;
&lt;TD&gt;tot_cnt&lt;/TD&gt;
&lt;TD&gt;22&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan="6"&gt;Desired result is to dynamically name the header(dates)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan="5"&gt;with a character varaible based on the month&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan="3"&gt;descending order. Like this&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;section&lt;/TD&gt;
&lt;TD&gt;_NAME_&lt;/TD&gt;
&lt;TD&gt;Month3&lt;/TD&gt;
&lt;TD&gt;Month2&lt;/TD&gt;
&lt;TD&gt;Month1&lt;/TD&gt;
&lt;TD&gt;Month0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;central&lt;/TD&gt;
&lt;TD&gt;tot_cnt&lt;/TD&gt;
&lt;TD&gt;22&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;TD&gt;88&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you have variable in your data with the numbers like 0, 1, 2 you can use that variable as an ID variable and combine that with a PREFIX option in Proc transpose to generate the headings (though suspect with multiple records whether you get the desired one)&lt;/P&gt;
&lt;PRE&gt;proc transpose data=have out=want let
   prefix=month;
   by section;
   var tot_cnt;
   id month_sort;
run;&lt;/PRE&gt;
&lt;P&gt;which duplicates your last version.&lt;/P&gt;
&lt;P&gt;If part of your problem is to get the months then the date I provided above and intck function returns intervals:&lt;/P&gt;
&lt;P&gt;Months_previous = intck('month',dateval, '01APR2020'd);&lt;/P&gt;
&lt;P&gt;form example. I am not going to use TODAY(), which returns the current date and might be used to generate dynamic results as the the values you provided are all apparently in 2020 and the 'months' would be 18 to 12 which does not go along with "4" in any way. You could filter you data to only use the Months_previous in the range you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Not quite sure of your statement regarding formatting &amp;lt;&amp;gt;&amp;nbsp; Are you saying begin the code with &amp;lt;&amp;gt; and end it with &amp;lt;/&amp;gt;&amp;nbsp; as in html??&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No. Above the message window you type in on this forum should be a row of icons. The 7th one looks like &amp;lt;/&amp;gt;. Click on that an you get a text box to paste text into.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 23:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736287#M229338</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-21T23:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: Rename dynamic month to char and order desc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736289#M229339</link>
      <description>&lt;P&gt;Create variable month as a numerical column with a SAS Date value (count of days since 1/1/1960). In doing so you can then easily determine the max month in your data, use SAS calendar functions like intnx() to easily substract 3 months from your max date and because the internal value is now numerical and just a count of days any reporting will sort the months according to the numbers and not the strings (month names) so you get what you want.&lt;/P&gt;
&lt;P&gt;And last but not least: You don't need to transpose your data for reporting. The Proc's for reporting will do all of this for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below some sample code hopefully pointing you into the right direction.&lt;/P&gt;
&lt;P&gt;Informat monyy5. instructs SAS to interpret the source string as a date and convert it to a SAS Date value, Format monyy5. instructs SAS to print the SAS Date value (just a number, count of days since 1/1/1960) formatted as mmmyy.&lt;/P&gt;
&lt;P&gt;You don't need variable month_count anymore as now that the value in month is numerical it will sort as you'd expect.&lt;/P&gt;
&lt;P&gt;And for numerical values like tot_cnt: NEVER define a length other than 8 unless you really know what you're doing. For numerical values the length does not define the numbers of digits but it defines the number of bytes used for storing the number. Anything other than the default length of 8 might lead to unexpected results (loss of numerical precision) unless you fully understand what you're doing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* populate month column with a SAS Data value - count of days since 1/1/1960 */
data have;
  attrib 
    section length=$25 
    month length=8 informat=monyy5. format=monyy5.
    tot_cnt length=8 
    ;
  input section -- tot_cnt;
  datalines;
central JAN20 10 3
central JAN20 22 3
central FEB20 30 2
central FEB20 88 2
central MAR20 30 1
central MAR20 88 1
central APR20 30 0
central APR20 88 0
;

/* determine max. month value in data */
data _null_;
  set have(keep=month) end=last;
  retain max_month;
  max_month=max(max_month,month);
  if last then
    do;
      /* use intnx() calendar function to substract 3 months */
      start_month=intnx('month',max_month,-3,'b');
      /* create and populate macro variables for later use */
      call symputx('max_month',max_month);
      call symputx('start_month',start_month);
      /* write max month and begin month to SAS log */
      put "Max Month   - Formatted: " max_month monyy5. 
          ", internal value count of days: " max_month 32. -l;
      put "Start Month - Formatted: " start_month monyy5. 
          ", internal value count of days: " start_month 32. -l;
    end;
run;

/* print content of macro vars (SAS Date values, count of days) */
%put &amp;amp;=max_month;
%put &amp;amp;=start_month;

/* and now do your reporting using a Proc like Report, Tabulate or whatever is suitable */
proc report data=have(where=(month&amp;gt;=&amp;amp;start_month));
....&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Apr 2021 23:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736289#M229339</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-21T23:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Rename dynamic month to char and order desc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736351#M229377</link>
      <description>&lt;P&gt;Maxim 2: Read the Log.&lt;/P&gt;
&lt;P&gt;Your transpose fails because of duplicate ID values per group:&lt;/P&gt;
&lt;PRE&gt; 73         data have;
 74         length section $25
 75         month_ $5
 76         tot_cnt 3
 77         month_sort 8;
 78         input section -- month_sort;
 79         datalines;
 
 NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
 NOTE: The data set WORK.HAVE has 8 observations and 4 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 89         ;
 90         run;
 91         proc transpose data=have out=want let;
 92         id month_;
 93         var tot_cnt;
 94         by section;
 95         run;
 
 WARNING: The ID value "JAN20" occurs twice in derselben BY-Gruppe.
 WARNING: The ID value "FEB20" occurs twice in derselben BY-Gruppe.
 WARNING: The ID value "MAR20" occurs twice in derselben BY-Gruppe.
 WARNING: The ID value "APR20" occurs twice in derselben BY-Gruppe.
 NOTE: The above message was for the following BY group:
       section=central
 NOTE: There were 8 observations read from the data set WORK.HAVE.
 NOTE: The data set WORK.WANT has 1 observations and 6 variables.
 NOTE:  Verwendet wurde: PROZEDUR TRANSPOSE - (Gesamtverarbeitungszeit):
       real time           0.01 seconds
       cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;So you first need to decide how to deal with the duplicates (calculate a sum, a count, a mean?).&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 09:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-dynamic-month-to-char-and-order-desc/m-p/736351#M229377</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-22T09:02:26Z</dc:date>
    </item>
  </channel>
</rss>

