<?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 date 201001 to JAN2010 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807208#M318197</link>
    <description>&lt;P&gt;Maxim 2: Read the Log.&lt;/P&gt;
&lt;PRE&gt; 69         data xxx;
 70         fle = 'xxx_xxxx_2020'; /*filename*/
 71         a = scan(fle,-1,'_');
 72         a1=(input(scan(fle,-1,'_'),best12.));
 73         a2=(input(scan(fle,-1,'_'),6.));
 74         a3=(put(scan(fle,-1,'_'),monyy7.));
                                     _______
                                     484
 NOTE 484-185: Format $MONYY was not found or could not be loaded.
&lt;/PRE&gt;
&lt;P&gt;The fact that the data step compiler looked for a character format tells you that you wanted to apply a numeric format to a character value. The compiler then tries to correct your mistake and goes looking for a fitting character format, which is not there (in this case).&lt;/P&gt;
&lt;P&gt;Before you continue I&amp;nbsp;&lt;STRONG&gt;VERY STRONGLY&amp;nbsp;&lt;/STRONG&gt;recommend that you study &lt;A href="https://documentation.sas.com/doc/de/pgmsascdc/9.4_3.5/etsug/etsug_tsdata_sect006.htm" target="_blank" rel="noopener"&gt;this&lt;/A&gt; first to get an understanding how dates and times are represented in SAS.&lt;/P&gt;
&lt;P&gt;Dates are counts of days, times and datetimes are counts of seconds. Dates and datetimes start at midnight 1960-01-01, while times start at midnight of a given day.&lt;/P&gt;
&lt;P&gt;A value of 2020 will therefore be interpreted by a date format as the 2020th day after 1960-01-01, which happens to be&amp;nbsp;&lt;SPAN&gt;1965-07-13.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Apr 2022 17:12:43 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-04-11T17:12:43Z</dc:date>
    <item>
      <title>Convert date 201001 to JAN2010</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807191#M318180</link>
      <description>Hi All,&lt;BR /&gt;I am trying to convert a char date value to MONyy7.&lt;BR /&gt;&lt;BR /&gt;I am not able to get the desired output.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Data _NULL_;&lt;BR /&gt;Month = intnx(‘month’, Today(), -13);&lt;BR /&gt;Put monyy7.;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;Output ::::: MAR2021&lt;BR /&gt;&lt;BR /&gt;I am reading file names from a dataset.&lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;Data Month;&lt;BR /&gt;Mnth = xxx_xxxxx_2010;&lt;BR /&gt;Dte = scan(‘month’,-1,’_’);&lt;BR /&gt;Dte1=(input(scan(‘Month’,Best12.);&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;I’m not able to apply any of the date informats tried Anydttdtm and anydttdte&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Kindly suggest</description>
      <pubDate>Mon, 11 Apr 2022 16:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807191#M318180</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-04-11T16:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date 201001 to JAN2010</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807196#M318185</link>
      <description>Hi All,&lt;BR /&gt;&lt;BR /&gt;I missed to complete the scan in the previous post please find the completed and working&lt;BR /&gt;Data Month;&lt;BR /&gt;Mnth = xxx_xxxxx_2010;&lt;BR /&gt;Dte = scan(‘month’,-1,’_’);&lt;BR /&gt;Dte1=(input(scan(‘Month’,-1,’_’),Best12.);&lt;BR /&gt;Run;</description>
      <pubDate>Mon, 11 Apr 2022 16:30:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807196#M318185</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-04-11T16:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date 201001 to JAN2010</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807197#M318186</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _NULL_;
Month = intnx('month', Today(), -13);
Put monyy7.;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This doesn't work, and the LOG should report an error. You have to tell the PUT statement what variable you want it to PUT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I am reading file names from a dataset.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Data Month;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mnth = xxx_xxxxx_2010;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dte = scan(‘month’,-1,’_’);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dte1=(input(scan(‘Month’,Best12.);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Run;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I’m not able to apply any of the date informats tried Anydttdtm and anydttdte&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What is xxx_xxxxx_2010? I don't know what this is, so I am not surprised that informats cannot work with it. Day of the month is 3 characters and month is 5 characters? Or month is 3 characters and day of month is 5 characters? Please give us an actual example of this text string.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Furthermore, your code has mismatched parentheses, you also need to fix that before anything will work.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 16:41:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807197#M318186</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-11T16:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date 201001 to JAN2010</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807201#M318190</link>
      <description>&lt;P&gt;This cannot work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Month;
Mnth = xxx_xxxxx_2010;
Dte = scan(‘month’,-1,’_’);
Dte1=(input(scan(‘Month’,-1,’_’),Best12.);
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since you do not read any data from a dataset or an external file, there will not be a variable named xxx_xxxxx_2010, so you get a missing value in the first assignment.&lt;/P&gt;
&lt;P&gt;Then you use "funny" curly quotes which are not valid in code.&lt;/P&gt;
&lt;P&gt;If you want to separate the "2010" out from a string containing "xxx_xxxx_2010", you need to use (valid) quotes around the string in the first place; next, you have to use the variable in the next assignment, not a string containing "month". Also, avoid using unnecessary parentheses (start of the third assignment).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data month;
mnth = "xxx_xxxxx_2010";
dte = scan(mnth,-1,'_');
dte1 = input(scan(mnth,-1,'_'),best12.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For your initial question, this converts the string to a SAS date with the wanted format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
indate = "201001";
outdate = input(indate,yymmn6.);
format outdate monyy7.;
put outdate=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2022 16:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807201#M318190</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-11T16:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date 201001 to JAN2010</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807203#M318192</link>
      <description>Hi Kurt,&lt;BR /&gt;&lt;BR /&gt;Thank you for your quick response!&lt;BR /&gt;&lt;BR /&gt;Yes, you were correct, I missed putting xxx_xxxx_201001 in quotations.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Data _NULL_;&lt;BR /&gt;Month = intnx('month', Today(), -13);&lt;BR /&gt;Put Month monyy7.;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data xxx;&lt;BR /&gt;fle = 'xxx_xxxx_2020'; /*filename*/&lt;BR /&gt;a = scan(fle,-1,'_');&lt;BR /&gt;a1=(input(scan(fle,-1,'_'),best12.));&lt;BR /&gt;a2=(input(scan(fle,-1,'_'),6.));&lt;BR /&gt;a3=(put(scan(fle,-1,'_'),monyy7.));&lt;BR /&gt;format a1 monyy7. a2 monyy7. ;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Mon, 11 Apr 2022 16:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807203#M318192</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-04-11T16:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date 201001 to JAN2010</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807204#M318193</link>
      <description>Hi Paige,&lt;BR /&gt;&lt;BR /&gt;Thank you for your quick response!&lt;BR /&gt;Please find the corrected code below, but I m still not getting what I want to. i.e. convert 202003 to march2020&lt;BR /&gt;&lt;BR /&gt;Data _NULL_;&lt;BR /&gt;Month = intnx('month', Today(), -13);&lt;BR /&gt;Put Month monyy7.;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data xxx;&lt;BR /&gt;fle = 'xxx_xxxx_202003'; /*filename*/&lt;BR /&gt;a = scan(fle,-1,'_');&lt;BR /&gt;a1=(input(scan(fle,-1,'_'),best12.));&lt;BR /&gt;a2=(input(scan(fle,-1,'_'),6.));&lt;BR /&gt;a3=(put(scan(fle,-1,'_'),monyy7.));&lt;BR /&gt;a4=(input(scan(fle,-1,'_'),monyy7.));&lt;BR /&gt;format a1 monyy7. a2 monyy7. ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc contents data = xxx;run;</description>
      <pubDate>Mon, 11 Apr 2022 16:58:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807204#M318193</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-04-11T16:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date 201001 to JAN2010</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807205#M318194</link>
      <description>Hi Kurt,&lt;BR /&gt;&lt;BR /&gt;Thank you for your suggestion.&lt;BR /&gt;&lt;BR /&gt;I missed it earlier.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It's working for me now.&lt;BR /&gt;Tahnk you again!</description>
      <pubDate>Mon, 11 Apr 2022 17:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807205#M318194</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-04-11T17:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date 201001 to JAN2010</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807207#M318196</link>
      <description>&lt;P&gt;202003 is four digit year and two digit month, so you need the &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/leforinforref/p13mkc7m059u4kn1knl9nzpliaat.htm" target="_self"&gt;YYMMN. informat&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
    fle='xxx_xxxx_202003';
    month=input(scan(fle,-1,'_'),yymmn6.);
    format month monyy7.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 17:08:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807207#M318196</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-11T17:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date 201001 to JAN2010</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807208#M318197</link>
      <description>&lt;P&gt;Maxim 2: Read the Log.&lt;/P&gt;
&lt;PRE&gt; 69         data xxx;
 70         fle = 'xxx_xxxx_2020'; /*filename*/
 71         a = scan(fle,-1,'_');
 72         a1=(input(scan(fle,-1,'_'),best12.));
 73         a2=(input(scan(fle,-1,'_'),6.));
 74         a3=(put(scan(fle,-1,'_'),monyy7.));
                                     _______
                                     484
 NOTE 484-185: Format $MONYY was not found or could not be loaded.
&lt;/PRE&gt;
&lt;P&gt;The fact that the data step compiler looked for a character format tells you that you wanted to apply a numeric format to a character value. The compiler then tries to correct your mistake and goes looking for a fitting character format, which is not there (in this case).&lt;/P&gt;
&lt;P&gt;Before you continue I&amp;nbsp;&lt;STRONG&gt;VERY STRONGLY&amp;nbsp;&lt;/STRONG&gt;recommend that you study &lt;A href="https://documentation.sas.com/doc/de/pgmsascdc/9.4_3.5/etsug/etsug_tsdata_sect006.htm" target="_blank" rel="noopener"&gt;this&lt;/A&gt; first to get an understanding how dates and times are represented in SAS.&lt;/P&gt;
&lt;P&gt;Dates are counts of days, times and datetimes are counts of seconds. Dates and datetimes start at midnight 1960-01-01, while times start at midnight of a given day.&lt;/P&gt;
&lt;P&gt;A value of 2020 will therefore be interpreted by a date format as the 2020th day after 1960-01-01, which happens to be&amp;nbsp;&lt;SPAN&gt;1965-07-13.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 17:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807208#M318197</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-11T17:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date 201001 to JAN2010</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807210#M318199</link>
      <description>&lt;P&gt;Let's clean up your code and use the Insert SAS Code pop-up window so it is easier to read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xxx;
  fle = 'xxx_xxxx_202003';
  a = scan(fle,-1,'_');
  a1= input(a,best12.);
  a2= input(a,6.);
  a3= put(a,monyy7.);
  a4= input(a,monyy7.);
  format a1 monyy7. a2 monyy7. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you created 5 variables in that code. FLE, A and A3 are character variables.&amp;nbsp; A1, A2 and A4 are numeric variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FLE appears to be your source string.&lt;/P&gt;
&lt;P&gt;A is just just the part after the last underscore.&amp;nbsp; If there are no underscores then FLE and A are the same.&lt;/P&gt;
&lt;P&gt;So for A1 and A2 you are attempting the same thing it different ways.&amp;nbsp; With&amp;nbsp;A1 you attempted to use BEST as an informat, but BEST is the name of a FORMAT.&amp;nbsp; It you use it as an INFORMAT then SAS just treats it as an alias for the normal numeric informat.&lt;/P&gt;
&lt;P&gt;So you really ran this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a1= input(a,12.);
a2= input(a,6.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will convert the first 12 and first 6 bytes, respectively,&amp;nbsp; of A into numbers. Since INPUT() doesn't care if the informat width is larger than the length of the string you can just use the maximum width on your informat instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a1= input(a,32.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For your example value of FLE this means that A1 will have the number 202,003.&amp;nbsp; Which if you try to format that number as a date will be some time in the &lt;STRONG&gt;year 2513&lt;/STRONG&gt;.&amp;nbsp; So A1 and A2 are NOT the values you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The statement creating A3 does not make any sense.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a3= put(a,monyy7.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since A is a character variable and you are using a numeric format SAS will convert the characters in A into a number.&amp;nbsp; That will be the same number that represents some day in the 2513 that you got in A1 and A2. So A3 is meaningless.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The statement for A4 is closer. At least now you are trying to create a date value into A4 by using an date type informat.&amp;nbsp; Unfortunately the string you pulled from FLE is not in the right style for the MONYY informat.&amp;nbsp; You need to use the YYMMN informat instead.&amp;nbsp; That will recognized digit strings that follow the pattern yyyymm or yymm as dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in the end you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xxx;
  fle = 'xxx_xxxx_202003';
  date = input(scan(fle,-1,'_'),yymmn6.);
  date_str = put(date,monyy7.);
  format date monyy7.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2022 17:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807210#M318199</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-11T17:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date 201001 to JAN2010</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807272#M318244</link>
      <description>Hi Tom,&lt;BR /&gt;&lt;BR /&gt;Thank you for your quick response!&lt;BR /&gt;&lt;BR /&gt;I will try this too..&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Tue, 12 Apr 2022 02:23:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-201001-to-JAN2010/m-p/807272#M318244</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-04-12T02:23:47Z</dc:date>
    </item>
  </channel>
</rss>

