<?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: Convert YYYY-MM to MON-2020 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686558#M208358</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;I'm getting to where more than 2 %sysfunc/%qsysfunc calls in a single statement tells my I may want to reconsider something.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hmmm. Good point. I have often felt that it gets a bit fiddly when you have perhaps dozens of left and right parentheses. Now, was that parenthesis for &lt;EM&gt;this&lt;/EM&gt; function of for &lt;EM&gt;that&lt;/EM&gt; function?&amp;nbsp; Did I close that call or is this a third parameter for ... ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
    <pubDate>Thu, 24 Sep 2020 22:15:36 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2020-09-24T22:15:36Z</dc:date>
    <item>
      <title>Convert YYYY-MM to MON-2020</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686405#M208274</link>
      <description>&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;pre = put(year(intnx ('month', today(), -1)) ,8.)||'-'||put(month(intnx ('month', today(), -1)), z2.);&lt;BR /&gt;call symputx('prev', left(Trim(pre)));&lt;BR /&gt;cur = put(year(intnx ('month', today(), 0)) ,8.)||'-'||put(month(intnx ('month', today(), 0)), z2.);&lt;BR /&gt;call symputx('curr', left(Trim(cur)));&lt;BR /&gt;run;&lt;BR /&gt;%put &amp;amp;prev.;&lt;BR /&gt;%put &amp;amp;curr.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to convert 2020-08 to Aug-2020 and 2020-09 to Sep-2020?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 15:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686405#M208274</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2020-09-24T15:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYYY-MM to MON-2020</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686416#M208285</link>
      <description>&lt;P&gt;So if PRE is yesterday and CUR is today, and they are both obtained from the TODAY() function, there is no need for all this manipulation. And if you are creating macro variables, don't even format them (see below).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
&amp;nbsp;&amp;nbsp; &amp;nbsp; cur=today();
   &amp;nbsp;&amp;nbsp;pre=cur-1;
     call symputx('pre',pre); 
     call symputx('cur',cur);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, we get to the critical issue of formatting macro variables. Please see &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28&lt;/A&gt;. Macro variables should NOT be formatted. You gain nothing from this (unless you are using the formatting for labels or titles), but it takes you extra time to write the code for this. Again, you work extra hard to format macro variables, and do all these manipulations, when it is not necessary. Don't do it (except for titles or labels). Working extra to gain nothing is not the path I would choose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 16:08:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686416#M208285</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-24T16:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYYY-MM to MON-2020</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686451#M208308</link>
      <description>&lt;P&gt;Expanding on what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;said, once you have a proper SAS Date in your Macro variable, you just format as needed when you need it.&amp;nbsp; For example, the following code will give you (displayed) the MON-CCYY format you're looking for:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
     cur=today();
     pre=cur-1;
     call symputx('pre',pre); 
     call symputx('cur',cur);
run;

%PUT	%QSYSFUNC(SUBSTR(%QSYSFUNC(PUTN(&amp;amp;Pre, MONYY7.)), 1, 3))-%QSYSFUNC(SUBSTR(%QSYSFUNC(PUTN(&amp;amp;Pre, MONYY7.)), 4, 4));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 17:53:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686451#M208308</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-24T17:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYYY-MM to MON-2020</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686453#M208310</link>
      <description>&lt;P&gt;I wouldn't even both trying to get the hyphen in there, it is much easier (and just as understandable for people viewing the results) to format as MONYY7. without the hyphen if you need it in titles or labels. Less work, in my mind, to get equally usable results, is always preferable.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 18:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686453#M208310</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-24T18:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYYY-MM to MON-2020</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686485#M208327</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I wouldn't even both trying to get the hyphen in there, it is much easier (and just as understandable for people viewing the results) to format as MONYY7. without the hyphen if you need it in titles or labels. Less work, in my mind, to get equally usable results, is always preferable.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Agree.&lt;/P&gt;
&lt;P&gt;If the hyphen were that critical I would likely make a custom Format and skip that many %sysfunc %qsysfunc calls in one statement. I'm getting to where more than 2 %sysfunc/%qsysfunc calls in a single statement tells my I may want to reconsider something.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 19:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686485#M208327</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-24T19:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYYY-MM to MON-2020</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686498#M208335</link>
      <description>&lt;P&gt;The DATE11. format will generate dd-MON-yyyy.&amp;nbsp; You could then just strip off the first three characters. And if you really want Sep instead of SEP you could call PROPCASE() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let want=%sysfunc(propcase(%substr(%sysfunc(today(),date11.),4)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;433   %put &amp;amp;=want;
WANT=Sep-2020
&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Sep 2020 19:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686498#M208335</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-24T19:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYYY-MM to MON-2020</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686556#M208356</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I wouldn't even both trying to get the hyphen in there, it is much easier (and just as understandable for people viewing the results) to format as MONYY7. without the hyphen if you need it in titles or labels. Less work, in my mind, to get equally usable results, is always preferable.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yeah, I think I would agree with you that 24SEP is just as understandable for most people as 24-SEP, and,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Less work, in my mind, to get equally usable results, is always preferable.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;would be difficult to argue with.&amp;nbsp; Programs have to be maintained, and, who knows, the next guy may not be as facile with macro functions which could lead to mis-representations of data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 22:11:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686556#M208356</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-24T22:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYYY-MM to MON-2020</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686558#M208358</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;I'm getting to where more than 2 %sysfunc/%qsysfunc calls in a single statement tells my I may want to reconsider something.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hmmm. Good point. I have often felt that it gets a bit fiddly when you have perhaps dozens of left and right parentheses. Now, was that parenthesis for &lt;EM&gt;this&lt;/EM&gt; function of for &lt;EM&gt;that&lt;/EM&gt; function?&amp;nbsp; Did I close that call or is this a third parameter for ... ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 22:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686558#M208358</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-24T22:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYYY-MM to MON-2020</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686560#M208360</link>
      <description>&lt;P&gt;Ah.&amp;nbsp; Very good.&amp;nbsp; Much better than what I proposed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 22:17:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686560#M208360</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-24T22:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYYY-MM to MON-2020</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686608#M208399</link>
      <description>&lt;P&gt;You can use Picture format to get your desired outcome.&lt;/P&gt;&lt;P&gt;proc format ;&lt;BR /&gt;picture newfmt(default=6)&lt;BR /&gt;other='%b-%y'(datatype=date);&lt;BR /&gt;run;&lt;BR /&gt;data _null_;&lt;/P&gt;&lt;P&gt;call symputx('prev', put(intnx ('month', today(), -1 ),newfmt.));&lt;BR /&gt;call symputx('curr', put(intnx ('month', today(), 0 ),newfmt.));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%put &amp;amp;prev.;&lt;BR /&gt;%put &amp;amp;curr.;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;34 %put &amp;amp;prev.;&lt;BR /&gt;SYMBOLGEN: Macro variable PREV resolves to Aug-20&lt;BR /&gt;Aug-20&lt;BR /&gt;35 %put &amp;amp;curr.;&lt;BR /&gt;SYMBOLGEN: Macro variable CURR resolves to Sep-20&lt;BR /&gt;Sep-20&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 05:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686608#M208399</guid>
      <dc:creator>SK_11</dc:creator>
      <dc:date>2020-09-25T05:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYYY-MM to MON-2020</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686705#M208427</link>
      <description>Thanks Sumit, but how to display Prev as AUG-2020 and Curr as SEP-2020 instead of AUG-20 and SEP-2020</description>
      <pubDate>Fri, 25 Sep 2020 14:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686705#M208427</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2020-09-25T14:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYYY-MM to MON-2020</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686711#M208431</link>
      <description>I found the trick:&lt;BR /&gt;proc format ;&lt;BR /&gt;picture newfmt(default=10)&lt;BR /&gt;other='%b-%Y'(datatype=date);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;This gets me the desired output.</description>
      <pubDate>Fri, 25 Sep 2020 14:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686711#M208431</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2020-09-25T14:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYYY-MM to MON-2020</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686754#M208445</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16600"&gt;@SASPhile&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I found the trick:&lt;BR /&gt;proc format ;&lt;BR /&gt;picture newfmt(default=10)&lt;BR /&gt;other='%b-%Y'(datatype=date);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;This gets me the desired output.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Default = 8 would likely be better to prevent leading spaces.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 16:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYYY-MM-to-MON-2020/m-p/686754#M208445</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-25T16:28:26Z</dc:date>
    </item>
  </channel>
</rss>

