<?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: How to convert the Char to Date format? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-the-Char-to-Date-format/m-p/492693#M129517</link>
    <description>&lt;P&gt;Here's an example of how to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Read it in as date time&lt;/P&gt;
&lt;P&gt;2. Extract date portion&lt;/P&gt;
&lt;P&gt;3. Extract time portion&lt;/P&gt;
&lt;P&gt;4. Keep as datetime and format as date to view&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
x="2018-08-31 00:00:00";

*import and convert to date time variable;
y_datetime=input(x, anydtdtm.);

*get only the date part;
y_date=datepart(y_datetime);

*get only the time part;
y_time=timepart(y_datetime);

*keep as datetime and format as date;
Y_formatted = Y_datetime;

format y_datetime datetime. y_date date9. y_time time. y_formatted dtdate9.;
run;

proc print data=have;run;&lt;/PRE&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.HAVE" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;x&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;y_datetime&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;y_date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;y_time&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;Y_formatted&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;2018-08-31 00:00:00&lt;/TD&gt;
&lt;TD class="r data"&gt;31AUG18:00:00:00&lt;/TD&gt;
&lt;TD class="r data"&gt;31AUG2018&lt;/TD&gt;
&lt;TD class="r data"&gt;0:00:00&lt;/TD&gt;
&lt;TD class="r data"&gt;31AUG2018&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&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/230772"&gt;@New_SAS_user76&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi! I would like to seek your help to solve my question!&lt;/P&gt;
&lt;P&gt;My&amp;nbsp;existing variable format is Char "2018-08-31 00:00:00" and I want to convert it to SAS Date9. format. Please see my code as below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data Temp;&lt;/P&gt;
&lt;P&gt;set T;&lt;/P&gt;
&lt;P&gt;format AA date9.;&lt;/P&gt;
&lt;P&gt;AA=input(char,MMDDYY10.);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Really hope you can help me! Thanks a lot!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 05 Sep 2018 15:05:07 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-09-05T15:05:07Z</dc:date>
    <item>
      <title>How to convert the Char to Date format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-the-Char-to-Date-format/m-p/492570#M129455</link>
      <description>&lt;P&gt;Hi! I would like to seek your help to solve my question!&lt;/P&gt;&lt;P&gt;My&amp;nbsp;existing variable format is Char "2018-08-31 00:00:00" and I want to convert it to SAS Date9. format. Please see my code as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Temp;&lt;/P&gt;&lt;P&gt;set T;&lt;/P&gt;&lt;P&gt;format AA date9.;&lt;/P&gt;&lt;P&gt;AA=input(char,MMDDYY10.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really hope you can help me! Thanks a lot!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 09:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-the-Char-to-Date-format/m-p/492570#M129455</guid>
      <dc:creator>New_SAS_user76</dc:creator>
      <dc:date>2018-09-05T09:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert the Char to Date format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-the-Char-to-Date-format/m-p/492572#M129457</link>
      <description>&lt;PRE&gt;data want;
  char_date="2018-08-31 00:00:00";
  num_date=input(substr(char_date,1,10),yymmdd10.);
  format num_date date9.;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Sep 2018 09:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-the-Char-to-Date-format/m-p/492572#M129457</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-05T09:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert the Char to Date format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-the-Char-to-Date-format/m-p/492582#M129462</link>
      <description>&lt;P&gt;Actually, the informat "substrings" on its own:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input char :$20.;
cards;
2018-08-31 00:00:00
;
run;

data want;
set have;
format aa date9.;
aa = input(char,yymmdd10.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Sep 2018 10:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-the-Char-to-Date-format/m-p/492582#M129462</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-05T10:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert the Char to Date format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-the-Char-to-Date-format/m-p/492583#M129463</link>
      <description>&lt;P&gt;True, but you know my thoughts on implicit anything.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 10:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-the-Char-to-Date-format/m-p/492583#M129463</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-05T10:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert the Char to Date format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-the-Char-to-Date-format/m-p/492584#M129464</link>
      <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 10:47:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-the-Char-to-Date-format/m-p/492584#M129464</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-05T10:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert the Char to Date format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-the-Char-to-Date-format/m-p/492693#M129517</link>
      <description>&lt;P&gt;Here's an example of how to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Read it in as date time&lt;/P&gt;
&lt;P&gt;2. Extract date portion&lt;/P&gt;
&lt;P&gt;3. Extract time portion&lt;/P&gt;
&lt;P&gt;4. Keep as datetime and format as date to view&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
x="2018-08-31 00:00:00";

*import and convert to date time variable;
y_datetime=input(x, anydtdtm.);

*get only the date part;
y_date=datepart(y_datetime);

*get only the time part;
y_time=timepart(y_datetime);

*keep as datetime and format as date;
Y_formatted = Y_datetime;

format y_datetime datetime. y_date date9. y_time time. y_formatted dtdate9.;
run;

proc print data=have;run;&lt;/PRE&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.HAVE" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;x&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;y_datetime&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;y_date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;y_time&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;Y_formatted&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;2018-08-31 00:00:00&lt;/TD&gt;
&lt;TD class="r data"&gt;31AUG18:00:00:00&lt;/TD&gt;
&lt;TD class="r data"&gt;31AUG2018&lt;/TD&gt;
&lt;TD class="r data"&gt;0:00:00&lt;/TD&gt;
&lt;TD class="r data"&gt;31AUG2018&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&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/230772"&gt;@New_SAS_user76&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi! I would like to seek your help to solve my question!&lt;/P&gt;
&lt;P&gt;My&amp;nbsp;existing variable format is Char "2018-08-31 00:00:00" and I want to convert it to SAS Date9. format. Please see my code as below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data Temp;&lt;/P&gt;
&lt;P&gt;set T;&lt;/P&gt;
&lt;P&gt;format AA date9.;&lt;/P&gt;
&lt;P&gt;AA=input(char,MMDDYY10.);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Really hope you can help me! Thanks a lot!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 05 Sep 2018 15:05:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-the-Char-to-Date-format/m-p/492693#M129517</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-05T15:05:07Z</dc:date>
    </item>
  </channel>
</rss>

