<?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 time from YYMMDD10 to YYMMDDN8 in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Convert-date-time-from-YYMMDD10-to-YYMMDDN8/m-p/732796#M28514</link>
    <description>&lt;P&gt;SAS has two types of variables floating point numbers and fixed length character strings.&amp;nbsp; If you variable has the YYMMDD10. format specification attached to it and displays as the 10 character string with hyphens, for example "2021-04-10", then it is a numeric variable and the value stored is the number of days since 1960.&amp;nbsp; &amp;nbsp;If you have another numeric variable that has the YYMMDDN8. format attached to it then the same number would be displayed as the 8 character string "20210410".&amp;nbsp; So to make the new variable have the same date as the old one just assign the value without modification.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date2=date;
format date2 yymmddn8.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The INPUT() function is for using an informat to convert text into values.&amp;nbsp; If you call it with a numeric variable instead of a character variable then SAS will auto convert the number into a string for the INPUT() function to operate one.&amp;nbsp; It will do this using the BEST12. format, not any format that might or might not be attached to the variable.&amp;nbsp; So a date value of '10APR2021'd (which is the number&amp;nbsp;22,380) would become string "&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;22380"&amp;nbsp; (notice the 7 leading spaces).&amp;nbsp; The first 10 characters of that string cannot be interpreted by the YYMMDD10 informat as a valid date.&lt;/P&gt;</description>
    <pubDate>Sat, 10 Apr 2021 20:02:47 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-04-10T20:02:47Z</dc:date>
    <item>
      <title>Convert date time from YYMMDD10 to YYMMDDN8</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-date-time-from-YYMMDD10-to-YYMMDDN8/m-p/732792#M28513</link>
      <description>&lt;P&gt;Hi everyone&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a column in my data set that is recognized by SAS as numeric and where the values are in the format of YYYY-MM-DD. I would like to convert it into YYYYMMDD format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To do so I took the variable with the current format&amp;nbsp;YYMMDD10 and create a new variable "date2" which is already numeric and in the format that I want it to be,&amp;nbsp;YYMMDDN8. However, when I run the code, the "date2" stays empty.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you tell me how I can solve this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to either a) transform the current date variable to&amp;nbsp;YYMMDDN8 or b) create a new variable with&amp;nbsp;YYMMDDN8 format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I used:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data xyz;
set xy;
date2= input(date, yymmdd10.);
format date2 YYMMDDN8.;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Apr 2021 19:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-date-time-from-YYMMDD10-to-YYMMDDN8/m-p/732792#M28513</guid>
      <dc:creator>sasmme</dc:creator>
      <dc:date>2021-04-10T19:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date time from YYMMDD10 to YYMMDDN8</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-date-time-from-YYMMDD10-to-YYMMDDN8/m-p/732796#M28514</link>
      <description>&lt;P&gt;SAS has two types of variables floating point numbers and fixed length character strings.&amp;nbsp; If you variable has the YYMMDD10. format specification attached to it and displays as the 10 character string with hyphens, for example "2021-04-10", then it is a numeric variable and the value stored is the number of days since 1960.&amp;nbsp; &amp;nbsp;If you have another numeric variable that has the YYMMDDN8. format attached to it then the same number would be displayed as the 8 character string "20210410".&amp;nbsp; So to make the new variable have the same date as the old one just assign the value without modification.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date2=date;
format date2 yymmddn8.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The INPUT() function is for using an informat to convert text into values.&amp;nbsp; If you call it with a numeric variable instead of a character variable then SAS will auto convert the number into a string for the INPUT() function to operate one.&amp;nbsp; It will do this using the BEST12. format, not any format that might or might not be attached to the variable.&amp;nbsp; So a date value of '10APR2021'd (which is the number&amp;nbsp;22,380) would become string "&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;22380"&amp;nbsp; (notice the 7 leading spaces).&amp;nbsp; The first 10 characters of that string cannot be interpreted by the YYMMDD10 informat as a valid date.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Apr 2021 20:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-date-time-from-YYMMDD10-to-YYMMDDN8/m-p/732796#M28514</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-10T20:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date time from YYMMDD10 to YYMMDDN8</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-date-time-from-YYMMDD10-to-YYMMDDN8/m-p/732799#M28515</link>
      <description>&lt;P&gt;Amazing! Thank you so much!!! Problem solved.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Apr 2021 20:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-date-time-from-YYMMDD10-to-YYMMDDN8/m-p/732799#M28515</guid>
      <dc:creator>sasmme</dc:creator>
      <dc:date>2021-04-10T20:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date time from YYMMDD10 to YYMMDDN8</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Convert-date-time-from-YYMMDD10-to-YYMMDDN8/m-p/732803#M28516</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/377672"&gt;@sasmme&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a column in my data set that is recognized by SAS as numeric and where the values are in the format of YYYY-MM-DD. I would like to convert it into YYYYMMDD format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To do so I took the variable with the current format&amp;nbsp;YYMMDD10 and create a new variable "date2" which is already numeric and in the format that I want it to be,&amp;nbsp;YYMMDDN8. However, when I run the code, the "date2" stays empty.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you tell me how I can solve this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to either a) transform the current date variable to&amp;nbsp;YYMMDDN8 or b) create a new variable with&amp;nbsp;YYMMDDN8 format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code I used:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data xyz;
set xy;
date2= input(date, yymmdd10.);
format date2 YYMMDDN8.;
run;&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;No need to create a new variable; just change the format on date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xyz;
set xy;
format date YYMMDDN8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or better yet if you have large data sets&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets library=work;
modify xy;
format date yymmddn8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Apr 2021 22:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Convert-date-time-from-YYMMDD10-to-YYMMDDN8/m-p/732803#M28516</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-10T22:06:33Z</dc:date>
    </item>
  </channel>
</rss>

