<?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 YYMMDD to other formats in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308185#M66097</link>
    <description>Thanks Laurie, Your solution worked a treat! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Mon, 31 Oct 2016 03:34:10 GMT</pubDate>
    <dc:creator>Haydn</dc:creator>
    <dc:date>2016-10-31T03:34:10Z</dc:date>
    <item>
      <title>Convert YYMMDD to other formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308176#M66092</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I have a date at the beginning of my code. %let crundate=161028;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to use the above to return '28Oct2016' as a date&lt;/P&gt;&lt;P&gt;&amp;nbsp;and "28 October 2016" as a string&lt;/P&gt;&lt;P&gt;&amp;nbsp;and "oct2016" as a string&lt;/P&gt;&lt;P&gt;and if possible the 1st and last day of the month (in this case October)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I use this&amp;nbsp; %let ssrundate=%substr(&amp;amp;crundate,1,4);&amp;nbsp;&amp;nbsp; to return '1610'. But I cant seem to get any other formats I want.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The reason I need this, is that there a numerous sas files dropped into my folders and all have different naming conventions.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Examples: FileAoct2016, FileB28Oct2016, FileC1610 (FileA, FileB ect are not the actual names, but the dates at the end are actual values).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In addition I would like to use the 161028 to returns date values as mentioned above&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%StartofMonth = &amp;amp;crundate ( this would return 01Oct2016) atm I'm coding this as&amp;nbsp; %let StartofMonth= "01Oct2016"d;&lt;/P&gt;&lt;P&gt;%EndofMonth = &amp;amp;crundate ( this would return 31Oct2016) atm I'm coding this as&amp;nbsp; %let StartofMonth= "31Oct2016"d;&lt;/P&gt;&lt;P&gt;%Drundate= &amp;amp;crundate ( this would return oct16) atm I'm coding this as %let Drundate= oct16;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2016 00:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308176#M66092</guid>
      <dc:creator>Haydn</dc:creator>
      <dc:date>2016-10-31T00:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYMMDD to other formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308177#M66093</link>
      <description>&lt;P&gt;SAS does it all very nicely for you, with just a couple of additions, assuming I've understood you correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For a start, it makes things much easier if you store your date value as "days since 1 Jan 1960", or 20755 in this case. The easiest way to do this is to use the %sysevalf function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rundate = %sysevalf("28oct2016"d);  /* which requires you to reformat your date, of course */&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rundate = %sysfunc(inputn(161028, yymmdd6.));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, the intnx function is your friend. This will return the beginning, middle or end of a period ('month' in this case, obviously). Couple that with some formats and you're away.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let startofmonth = %sysfunc(intnx(month, &amp;amp;rundate, 0, b), date9.);
%let endofmonth = %sysfunc(intnx(month, &amp;amp;rundate, 0, e), date9.);
%let drundate = %sysfunc(putn(&amp;amp;rundate, monyy5.));

%put &amp;amp;startofmonth &amp;amp;endofmonth &amp;amp;drundate;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This displays:&lt;/P&gt;&lt;PRE&gt;01OCT2016 31OCT2016 OCT16&lt;/PRE&gt;&lt;P&gt;Note that this will return 1OCT2016 etc. To convert that in macro code is a little ugly, but will be reliable:&lt;/P&gt;&lt;PRE&gt; %let endofmonth = %substr(&amp;amp;endofmonth, 1, 3)%lowcase(%substr(&amp;amp;endofmonth, 4, 2))%substr(&amp;amp;endofmonth, 6, 4);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to see&amp;nbsp;&lt;EM&gt;1 October 2016&lt;/EM&gt; instead (which doesn't require the substringing):&lt;/P&gt;&lt;PRE&gt;%let startofmonth = %sysfunc(intnx(month, &amp;amp;rundate, 0, b), worddatx.);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your other option, to return the year and month:&lt;/P&gt;&lt;PRE&gt;%put %sysfunc(putn(&amp;amp;rundate, yymmdd4.));&lt;BR /&gt;1610&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2016 01:43:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308177#M66093</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-10-31T01:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYMMDD to other formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308179#M66095</link>
      <description>Thanks for you reply,&lt;BR /&gt;&lt;BR /&gt;Sorry I should have mentioned that 161028 also still has to be returned as that is also appended to file names. Both %let rundate = %sysevalf("28oct2016"d); /* which requires you to reformat your date, of course */ and %let rundate = %sysfunc(inputn(161028, yymmdd6.)); return 20755. Was the above supposed to return that?</description>
      <pubDate>Mon, 31 Oct 2016 02:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308179#M66095</guid>
      <dc:creator>Haydn</dc:creator>
      <dc:date>2016-10-31T02:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYMMDD to other formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308181#M66096</link>
      <description>&lt;P&gt;Oh, I see. If you start off by converting your input string into a SAS date value, you have all the flexibility you need. So, starting off with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let crundate = 161028;&lt;/PRE&gt;&lt;P&gt;followed by:&lt;/P&gt;&lt;PRE&gt;%let rundate = %sysfunc(inputn(&amp;amp;crundate, yymmdd6.));&lt;/PRE&gt;&lt;P&gt;That will leave crundate effectively as a text string (although macro variables are untyped) and can be used as such, and rundate with a value of 20755. What I meant with the alternatives was that it was two ways of doing exactly the same thing. In retrospect, the second one seems closer to what you want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope I've made things a little clearer…&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2016 02:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308181#M66096</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-10-31T02:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYMMDD to other formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308185#M66097</link>
      <description>Thanks Laurie, Your solution worked a treat! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 31 Oct 2016 03:34:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308185#M66097</guid>
      <dc:creator>Haydn</dc:creator>
      <dc:date>2016-10-31T03:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYMMDD to other formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308187#M66098</link>
      <description>&lt;P&gt;Excellent. Glad to help. %sysfunc is really your friend.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2016 03:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308187#M66098</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-10-31T03:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYMMDD to other formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308906#M66361</link>
      <description>&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code that Laurie gave me works in that it returns date values&amp;nbsp;(thanks again Laurie). However, using the below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let crundate= 161028;&amp;nbsp;&lt;BR /&gt;%let irsbrundate = %sysfunc(inputn(&amp;amp;crundate, yymmdd6.));
%let StartofMonth = %sysfunc(intnx(month, &amp;amp;irsbrundate, 0, b), date9.);
%let EndofMonth = %sysfunc(intnx(month, &amp;amp;irsbrundate, 0, e), date9.);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;with&lt;/P&gt;&lt;PRE&gt;data reports.PartiFail&amp;amp;crundate;
set reports.PartiFail&amp;amp;crundate;

retain Start_of_Month&amp;amp;StartofMonth ;
format Start_of_Month date9.;
retain End_of_Month&amp;amp;EndofMonth;
format End_of_Month date9.;


run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Does not &amp;nbsp;return&amp;nbsp;values for Start_of_Month nor End_of_Month. "." are returned on every row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;However,&lt;/P&gt;&lt;PRE&gt;%let StartMonth= "01Oct2016"d;
%let EndMonth = "31Oct2016"d;&lt;/PRE&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data reports.PartiFail&amp;amp;crundate;
set reports.PartiFail&amp;amp;crundate;

retain Start_of_Month&amp;amp;StartMonth ;
format Start_of_Month date9.;
retain End_of_Month&amp;amp;EndMonth;
format End_of_Month date9.;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;does return date values (01OCT2016 and 31OCT2016).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking at SAS Macro Variable Viewer is SAS EG, StartMonth returns &amp;nbsp;"01Oct2016"d and StartofMonth&amp;nbsp;returns 01OCT2016.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there something else I need to do, so I dont have to hard code the first day of the month and last day of the month, based off crundate?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 22:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/308906#M66361</guid>
      <dc:creator>Haydn</dc:creator>
      <dc:date>2016-11-02T22:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Convert YYMMDD to other formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/309898#M66784</link>
      <description>&lt;P&gt;Ah - I think you've got the external and internal values of the variables mixed up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first block of code has them stored as the external representations. If you convert it to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let crundate= 161028; 
%let irsbrundate = %sysfunc(inputn(&amp;amp;crundate, yymmdd6.));
%let StartofMonth = %sysfunc(intnx(month, &amp;amp;irsbrundate, 0, b));
%let EndofMonth = %sysfunc(intnx(month, &amp;amp;irsbrundate, 0, e));
 with

data reports.PartiFail&amp;amp;crundate;
set reports.PartiFail&amp;amp;crundate;
retain Start_of_Month &amp;amp;StartofMonth ;&lt;BR /&gt;
format Start_of_Month date9.;
retain End_of_Month &amp;amp;EndofMonth;
format End_of_Month date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the intnx functions within the %sysfuncs no longer have the format applied to them, so the %sysfuncs only return the internal values.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 23:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-YYMMDD-to-other-formats/m-p/309898#M66784</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2016-11-07T23:20:30Z</dc:date>
    </item>
  </channel>
</rss>

