<?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 convert char to date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-char-to-date/m-p/685579#M207945</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;Please advice to convert the following to date .&lt;/P&gt;
&lt;P&gt;Thanks in Advance .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input DateToConvert $30.;
datalines;
January 1, 2020
January 1, 2020
January 1, 2020
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 22 Sep 2020 04:23:44 GMT</pubDate>
    <dc:creator>dennis_oz</dc:creator>
    <dc:date>2020-09-22T04:23:44Z</dc:date>
    <item>
      <title>convert char to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-char-to-date/m-p/685579#M207945</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;Please advice to convert the following to date .&lt;/P&gt;
&lt;P&gt;Thanks in Advance .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input DateToConvert $30.;
datalines;
January 1, 2020
January 1, 2020
January 1, 2020
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Sep 2020 04:23:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-char-to-date/m-p/685579#M207945</guid>
      <dc:creator>dennis_oz</dc:creator>
      <dc:date>2020-09-22T04:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: convert char to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-char-to-date/m-p/685583#M207946</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19264"&gt;@dennis_oz&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can go straight to the data that you want as a part of the Input process.&amp;nbsp; To wit:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
	INFILE		Datalines;
	INFORMAT	Input_Date	ANYDTDTE30.;
	FORMAT		Input_Date	DATE11.;
	LENGTH		Input_Date	8.;
	INPUT		Input_Date	&amp;amp;;
datalines;
January 1, 2020
February 28, 2020
September 21, 2020
November 15, 2020
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1600750303713.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49630iBD368B8A6848AC2D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1600750303713.png" alt="jimbarbour_0-1600750303713.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The trick here is the ampersand (&amp;amp;) on the Input statement.&amp;nbsp; The ampersand here tells SAS to treat a single space as part of the data.&amp;nbsp; Two spaces are required to separate input fields.&amp;nbsp; Absent the ampersand, SAS will stop at the first blank, and will treat "January 1, 2020" as three separate fields.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I then use an Informat, ANYDTDTE which is a sort of "Jack-of-All-Trades" input date format.&amp;nbsp; If it can be made sense of in terms of a date, SAS will do it.&amp;nbsp; The one caveat with ANYDTDTE is that you have to be aware of something like 12-08-2020. In some localities, 12-08-2020 represents December 8th, and in others August 12th.&amp;nbsp; How it is interpreted through ANYDTDTE is determined by your SAS options.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lastly, I formatted the date as DATE11, but that format is arbitrary.&amp;nbsp; Any valid SAS date will work fine for display purposes so long as it suits your needs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 04:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-char-to-date/m-p/685583#M207946</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-22T04:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: convert char to date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-char-to-date/m-p/685914#M208058</link>
      <description>&lt;P&gt;Oh, and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19264"&gt;@dennis_oz&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're in a situation where you really do need to take a character date from a SAS data set (instead of taking it from a text file as I did above), the approach is basically the same.&amp;nbsp; Again, I'm going to use ANYDTDTE30. as my informat but this time instead of an Input statement I will use the Input function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input DateToConvert $30.;
	datalines;
January 1, 2020
February 28, 2020
September 21, 2020
November 15, 2020
;
run;

DATA	Want_2;
	SET	Have;
	FORMAT		SAS_Date	DATE11.;
	SAS_Date	=	INPUT(DateToConvert, ANYDTDTE30.);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1600818867998.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49695iA110B653F24BD289/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1600818867998.png" alt="jimbarbour_0-1600818867998.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Notice the icon on the "SAS_Date" variable.&amp;nbsp; SAS does indeed regard this variable as a date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope one or the other of the above can serve as a solution for what you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 23:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-char-to-date/m-p/685914#M208058</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-22T23:56:09Z</dc:date>
    </item>
  </channel>
</rss>

