<?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: Converting Char variable to date format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-Char-variable-to-date-format/m-p/689926#M209792</link>
    <description>Thank you @ jimbarbour &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; that resolved my problem as well.</description>
    <pubDate>Thu, 08 Oct 2020 10:32:44 GMT</pubDate>
    <dc:creator>KarimaTouati</dc:creator>
    <dc:date>2020-10-08T10:32:44Z</dc:date>
    <item>
      <title>Converting Char variable to date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Char-variable-to-date-format/m-p/689762#M209699</link>
      <description>&lt;P&gt;Hello folks !&lt;/P&gt;&lt;P&gt;I would like to seek your help to solve my question ! I found many&amp;nbsp;&lt;SPAN&gt;threads and documentation on this subject, but none solved&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;my problem.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;My&amp;nbsp;existing variable format is Char "12021988"&amp;nbsp; and I want to convert it to SAS DDMMYY10. or date9. format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="data_Nais.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50326i853471E25384C6F9/image-size/large?v=v2&amp;amp;px=999" role="button" title="data_Nais.PNG" alt="data_Nais.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am strating from the variable "Date_Naissance" and extracting each day, month and year, concatinating all the three to get a new variable "Date_Naissance_1".&lt;/P&gt;&lt;P&gt;I used the below code :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Test_Naiss as select DATE_NAISSANCE,substr(DATE_NAISSANCE,5,3) as MONTH,
(case when calculated MONTH="Jan" then "01"
when calculated MONTH="Feb" then "02"
when calculated MONTH="Mar" then "03"
when calculated MONTH="Apr" then "04" 
when calculated MONTH="May" then "05"
when calculated MONTH="Jun" then "06"
when calculated MONTH="Jul" then "07"
when calculated MONTH="Aug" then "08"
when calculated MONTH="Sep" then "09"
when calculated MONTH="Oct" then "10" 
when calculated MONTH="Nov" then "11"
when calculated MONTH="Dec" then "12"
else ""
end) as MONTH_1,
substr(DATE_NAISSANCE,9,2) as DAY,
substr(DATE_NAISSANCE,25,4) as YEAR,
cats(calculated DAY,calculated MONTH_1,calculated YEAR) as Date_Naissance_1,
input(calculated Date_Naissance_1,10.) as Date_Naissance_2,
input(calculated Date_Naissance_1,DDMMYY10.) as Date_Naissance_3
From inputs.production082020;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I can not get the format needed.&lt;/P&gt;&lt;P&gt;Any help will be appreciated. Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 22:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Char-variable-to-date-format/m-p/689762#M209699</guid>
      <dc:creator>KarimaTouati</dc:creator>
      <dc:date>2020-10-07T22:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Char variable to date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Char-variable-to-date-format/m-p/689766#M209702</link>
      <description>&lt;P&gt;Actually I think your date_naissance_3 is correct but you did not assign a format to the value. So assign Format=ddmmyy10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think that you are stating your objective clearly. If the objective is to turn that really ugly DATE_NAISSANCE into an actual date then get the &lt;STRONG&gt;numeric&lt;/STRONG&gt; values of month, day and year then use the SAS function MDY to create a date value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this might work (obviously untested as I don't have your data)&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table Test_Naiss as select DATE_NAISSANCE,substr(DATE_NAISSANCE,5,3) as MONTH,
   (case 
      when calculated MONTH="Jan" then 01
      when calculated MONTH="Feb" then 02
      when calculated MONTH="Mar" then 03
      when calculated MONTH="Apr" then 04 
      when calculated MONTH="May" then 05
      when calculated MONTH="Jun" then 06
      when calculated MONTH="Jul" then 07
      when calculated MONTH="Aug" then 08
      when calculated MONTH="Sep" then 09
      when calculated MONTH="Oct" then 10 
      when calculated MONTH="Nov" then 11
      when calculated MONTH="Dec" then 12
      else .
   end) as MONTH_1,
   input(substr(DATE_NAISSANCE,9,2),best.) as DAY,
   input(substr(DATE_NAISSANCE,25,4),best.) as YEAR,
   MDY(month_1,Day,Year) as Date_Naissance_3 Format=ddmmyy10.
   From inputs.production082020;
Quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 22:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Char-variable-to-date-format/m-p/689766#M209702</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-07T22:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Char variable to date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Char-variable-to-date-format/m-p/689769#M209703</link>
      <description>&lt;P&gt;Your data is well formatted, so you're in luck.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't have all you data, but I typed in the first three.&amp;nbsp; Below is my program and below that my results.&amp;nbsp; I think this might be a simpler approach than all the CALCULATED fields you're using.&amp;nbsp; See what you think.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data	Dates_From_Text;
	LENGTH	Text_Date	$32;
	INPUT	Text_Date	&amp;amp;	$;
DATALINES;
Fri Feb 12 00:00:00 WAT 1988
Sat Aug 15 00:00:00 WAT 1970
Tue May 14 00:00:00 WAT 1985
;
RUN;

PROC	SQL;
	SELECT	INPUT(CATS(	SUBSTR(Text_Date, 9, 2),
						SUBSTR(Text_Date, 5, 4),
						SUBSTR(Text_Date, LENGTH(Text_Date) - 4),
						'd')
			, DATE9.)	AS	SAS_Date	FORMAT	mmddyyd10.
		FROM	Dates_From_Text;
QUIT;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results.&amp;nbsp; I formatted the results as mmddyyd10, but you can format them any way you like.&amp;nbsp; These are standard numeric SAS dates.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1602111693534.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50328iE7CC1F531C8C7CE3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1602111693534.png" alt="jimbarbour_0-1602111693534.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 23:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Char-variable-to-date-format/m-p/689769#M209703</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-07T23:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Char variable to date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Char-variable-to-date-format/m-p/689926#M209792</link>
      <description>Thank you @ jimbarbour &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; that resolved my problem as well.</description>
      <pubDate>Thu, 08 Oct 2020 10:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Char-variable-to-date-format/m-p/689926#M209792</guid>
      <dc:creator>KarimaTouati</dc:creator>
      <dc:date>2020-10-08T10:32:44Z</dc:date>
    </item>
  </channel>
</rss>

