<?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 numeric data to character in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-numeric-data-to-character/m-p/799454#M314365</link>
    <description>&lt;P&gt;If it's numeric with a datetime format you need the DATEPART() function which will extract the date portion alone for you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on what you're doing you could also apply a format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

date_var  = datepart(datetimeVariable);
format date_var date9.;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/411887"&gt;@JillChen0131&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a bunch of numeric data in this kind of format: 06NOV2019:00:00:00.000. I would like to get 06NOV2019. I tried to use put, but it did not work. Can anyone help with that?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Mar 2022 21:26:13 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-03-01T21:26:13Z</dc:date>
    <item>
      <title>Convert numeric data to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-numeric-data-to-character/m-p/799453#M314364</link>
      <description>&lt;P&gt;I have a bunch of numeric data in this kind of format: 06NOV2019:00:00:00.000. I would like to get 06NOV2019. I tried to use put, but it did not work. Can anyone help with that?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 21:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-numeric-data-to-character/m-p/799453#M314364</guid>
      <dc:creator>JillChen0131</dc:creator>
      <dc:date>2022-03-01T21:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Convert numeric data to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-numeric-data-to-character/m-p/799454#M314365</link>
      <description>&lt;P&gt;If it's numeric with a datetime format you need the DATEPART() function which will extract the date portion alone for you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on what you're doing you could also apply a format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

date_var  = datepart(datetimeVariable);
format date_var date9.;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/411887"&gt;@JillChen0131&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a bunch of numeric data in this kind of format: 06NOV2019:00:00:00.000. I would like to get 06NOV2019. I tried to use put, but it did not work. Can anyone help with that?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 21:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-numeric-data-to-character/m-p/799454#M314365</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-03-01T21:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: Convert numeric data to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-numeric-data-to-character/m-p/799461#M314370</link>
      <description>&lt;P&gt;So you a variable that contains the number of seconds since 1960 and you are currently use the DATETIME23.3 format to display it in ddMONyyyy:hh:mm:ss.uuu style?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to change how the value is displayed?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use the DTDATE9. format instead you will have it displayed in the style of ddMONyyyy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to convert it from number of seconds into number of days?&amp;nbsp; You can use the DATEPART() function to make that conversion.&amp;nbsp; Then you could use the regular DATE9. format instead to display the number of days since 1960 in ddMONyyyy style.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just want to create a 9 character variable from your existing datetime values then use the PUT() function with the DTDATE9. format.&amp;nbsp; You will need to create a new variable to do that since you cannot change the type of a variable.&amp;nbsp; Although you can rename variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;405   data test;
406     have='06NOV2019:00:00:00.000'dt;
407     format have datetime23.3 ;
408     want1 = have;
409     format want1 dtdate9.;
410     want2 = datepart(have);
411     format want2 date9.;
412     want3=want2;
413     format want3 yymmdd10.;
414     want4 = put(have,dtdate9.);
415     put 'Formatted' (_all_) (=/)
416      // 'RAW' / (have -- want3) (=comma14. /)
417     ;
418   run;

Formatted
have=06NOV2019:00:00:00.000
want1=06NOV2019
want2=06NOV2019
want3=2019-11-06
want4=06NOV2019

RAW
have=1,888,617,600
want1=1,888,617,600
want2=21,859
want3=21,859
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 22:05:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-numeric-data-to-character/m-p/799461#M314370</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-01T22:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: Convert numeric data to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-numeric-data-to-character/m-p/799589#M314433</link>
      <description>&lt;P&gt;Thanks for the detailed explaination&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 15:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-numeric-data-to-character/m-p/799589#M314433</guid>
      <dc:creator>JillChen0131</dc:creator>
      <dc:date>2022-03-02T15:43:21Z</dc:date>
    </item>
  </channel>
</rss>

