<?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 SAS char/numeric  with  structure YYYYMMDD  into sas date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-SAS-char-numeric-with-structure-YYYYMMDD-into-sas-date/m-p/828099#M327114</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to convert sas numeric/char&amp;nbsp; &amp;nbsp;into sas date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Error-&lt;/P&gt;
&lt;P&gt;29 &lt;BR /&gt;30 data ttt2;&lt;BR /&gt;31 set ttt1;&lt;BR /&gt;32 SAS_date=input(put(x,best.),yymmddn8.);&lt;BR /&gt;_________&lt;BR /&gt;485&lt;BR /&gt;NOTE 485-185: Informat YYMMDDN was not found or could not be loaded.&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;data ttt1;
x=20200418;
run;

data ttt2;
set ttt1;
SAS_date=input(put(x,best.),yymmddn8.);
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Suggest that any time you are attempting to use the put numeric value and input for date such as with:&lt;/P&gt;
&lt;PRE&gt;SAS_date=input(put(x,best.),yymmddn8.);&lt;/PRE&gt;
&lt;P&gt;That you 1) use a format other than BEST (large/small values may create exponential notation that none of the Date/time/datetime informats will like and 2) that you use the -L instruction to left justify the resulting text. Consider this example.&lt;/P&gt;
&lt;PRE&gt;data example;
   x=20200418;
   y=quote(put(x,best.));
run;&lt;/PRE&gt;
&lt;P&gt;The quote function places quotes around the value of the Put. Note that the result has &lt;STRONG&gt;4&lt;/STRONG&gt; leading spaces because the default Best uses a width of 12 and your value had 8 characters as an integer. That is because PUT with numeric values by default right justifies the result. So whatever INFORMAT attempts to use that result will first encounter 4 spaces and likely fail to read the values you want.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data example;
   x=20200418;
   z=input(put(x,best.),f8.);
run;&lt;/PRE&gt;
&lt;P&gt;Z has the value of 2020 because the first 8 characters were 4 spaces and then the first 4 digits of 20200418. So the Date informat would only see 2020 and almost certainly fail.&lt;/P&gt;
&lt;P&gt;The -L instruction to the Put function left justifies the result.&lt;/P&gt;
&lt;PRE&gt;data example;
   x=20200418;
   z=input(put(x,best. -L),f8.);
run;&lt;/PRE&gt;
&lt;P&gt;Personally instead of best I would use an 8. format with put if I expect 8 characters in the result which would be less likely to have issues for these reasons. But I still use a -L with the put just in case.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Aug 2022 14:07:21 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-08-10T14:07:21Z</dc:date>
    <item>
      <title>Convert SAS char/numeric  with  structure YYYYMMDD  into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SAS-char-numeric-with-structure-YYYYMMDD-into-sas-date/m-p/828057#M327098</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to convert sas numeric/char&amp;nbsp; &amp;nbsp;into sas date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Error-&lt;/P&gt;
&lt;P&gt;29 &lt;BR /&gt;30 data ttt2;&lt;BR /&gt;31 set ttt1;&lt;BR /&gt;32 SAS_date=input(put(x,best.),yymmddn8.);&lt;BR /&gt;_________&lt;BR /&gt;485&lt;BR /&gt;NOTE 485-185: Informat YYMMDDN was not found or could not be loaded.&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;data ttt1;
x=20200418;
run;

data ttt2;
set ttt1;
SAS_date=input(put(x,best.),yymmddn8.);
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 10:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SAS-char-numeric-with-structure-YYYYMMDD-into-sas-date/m-p/828057#M327098</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-08-10T10:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SAS char/numeric  with  structure YYYYMMDD  into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SAS-char-numeric-with-structure-YYYYMMDD-into-sas-date/m-p/828061#M327102</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ttt1;
   x = 20200418;
run;

data ttt2;
   set ttt1;
   SAS_date = input(put(x,8.), yymmdd8.);
   format SAS_date date9.;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Aug 2022 11:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SAS-char-numeric-with-structure-YYYYMMDD-into-sas-date/m-p/828061#M327102</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-10T11:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SAS char/numeric  with  structure YYYYMMDD  into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SAS-char-numeric-with-structure-YYYYMMDD-into-sas-date/m-p/828062#M327103</link>
      <description>&lt;P&gt;&lt;FONT color="#FF0000"&gt;In&lt;/FONT&gt;formats do not have the special "x" characters, they don't care about the delimiters or absence of them (exception: YYMMN). Formats, OTOH, need them.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 11:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SAS-char-numeric-with-structure-YYYYMMDD-into-sas-date/m-p/828062#M327103</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-08-10T11:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Convert SAS char/numeric  with  structure YYYYMMDD  into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-SAS-char-numeric-with-structure-YYYYMMDD-into-sas-date/m-p/828099#M327114</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to convert sas numeric/char&amp;nbsp; &amp;nbsp;into sas date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Error-&lt;/P&gt;
&lt;P&gt;29 &lt;BR /&gt;30 data ttt2;&lt;BR /&gt;31 set ttt1;&lt;BR /&gt;32 SAS_date=input(put(x,best.),yymmddn8.);&lt;BR /&gt;_________&lt;BR /&gt;485&lt;BR /&gt;NOTE 485-185: Informat YYMMDDN was not found or could not be loaded.&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;data ttt1;
x=20200418;
run;

data ttt2;
set ttt1;
SAS_date=input(put(x,best.),yymmddn8.);
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Suggest that any time you are attempting to use the put numeric value and input for date such as with:&lt;/P&gt;
&lt;PRE&gt;SAS_date=input(put(x,best.),yymmddn8.);&lt;/PRE&gt;
&lt;P&gt;That you 1) use a format other than BEST (large/small values may create exponential notation that none of the Date/time/datetime informats will like and 2) that you use the -L instruction to left justify the resulting text. Consider this example.&lt;/P&gt;
&lt;PRE&gt;data example;
   x=20200418;
   y=quote(put(x,best.));
run;&lt;/PRE&gt;
&lt;P&gt;The quote function places quotes around the value of the Put. Note that the result has &lt;STRONG&gt;4&lt;/STRONG&gt; leading spaces because the default Best uses a width of 12 and your value had 8 characters as an integer. That is because PUT with numeric values by default right justifies the result. So whatever INFORMAT attempts to use that result will first encounter 4 spaces and likely fail to read the values you want.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data example;
   x=20200418;
   z=input(put(x,best.),f8.);
run;&lt;/PRE&gt;
&lt;P&gt;Z has the value of 2020 because the first 8 characters were 4 spaces and then the first 4 digits of 20200418. So the Date informat would only see 2020 and almost certainly fail.&lt;/P&gt;
&lt;P&gt;The -L instruction to the Put function left justifies the result.&lt;/P&gt;
&lt;PRE&gt;data example;
   x=20200418;
   z=input(put(x,best. -L),f8.);
run;&lt;/PRE&gt;
&lt;P&gt;Personally instead of best I would use an 8. format with put if I expect 8 characters in the result which would be less likely to have issues for these reasons. But I still use a -L with the put just in case.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 14:07:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-SAS-char-numeric-with-structure-YYYYMMDD-into-sas-date/m-p/828099#M327114</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-10T14:07:21Z</dc:date>
    </item>
  </channel>
</rss>

