<?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 character date to YYYYMMDD date field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-date-to-YYYYMMDD-date-field/m-p/258301#M49720</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35631"&gt;@mlogan﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would create SAS date values from&amp;nbsp;those character dates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length c $10;
c='3/30/2015';
d=input(c,mmddyy10.);
format d yymmddn8.;
put d;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need a character string in YYYYMMDD format you can apply the PUT function to the SAS date value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dc=put(input(c,mmddyy10.),yymmddn8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For invalid dates the conversion will fail, though. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Mar 2016 17:59:18 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2016-03-22T17:59:18Z</dc:date>
    <item>
      <title>Convert character date to YYYYMMDD date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-date-to-YYYYMMDD-date-field/m-p/258293#M49717</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;My date field (Imported from Excel) written like 2/30/2015 and&amp;nbsp;have&amp;nbsp;$10. format. Can someone help me to convert it to 20150230 format please. Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 17:47:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-date-to-YYYYMMDD-date-field/m-p/258293#M49717</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-03-22T17:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character date to YYYYMMDD date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-date-to-YYYYMMDD-date-field/m-p/258301#M49720</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35631"&gt;@mlogan﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would create SAS date values from&amp;nbsp;those character dates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length c $10;
c='3/30/2015';
d=input(c,mmddyy10.);
format d yymmddn8.;
put d;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need a character string in YYYYMMDD format you can apply the PUT function to the SAS date value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dc=put(input(c,mmddyy10.),yymmddn8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For invalid dates the conversion will fail, though. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 17:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-date-to-YYYYMMDD-date-field/m-p/258301#M49720</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-22T17:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character date to YYYYMMDD date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-date-to-YYYYMMDD-date-field/m-p/258304#M49723</link>
      <description>Thanks Reinhard.</description>
      <pubDate>Tue, 22 Mar 2016 18:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-date-to-YYYYMMDD-date-field/m-p/258304#M49723</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-03-22T18:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character date to YYYYMMDD date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-date-to-YYYYMMDD-date-field/m-p/258321#M49729</link>
      <description>Hi Reinhard,&lt;BR /&gt;Would you please tell me what I have to do if I want to convert the existing column to YYMMDDN8. format without making a new column. Here in your example converting column 'c' without making a new column 'd'.</description>
      <pubDate>Tue, 22 Mar 2016 18:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-date-to-YYYYMMDD-date-field/m-p/258321#M49729</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-03-22T18:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character date to YYYYMMDD date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-date-to-YYYYMMDD-date-field/m-p/258326#M49732</link>
      <description>&lt;P&gt;You could drop the old (character) variable and rename the new (numeric) one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length c $10;
c='3/30/2015';
run;

data want;
set have;
d=input(c,mmddyy10.);
format d yymmddn8.;
drop c;
rename d=c;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your goal is a character variable (such as DC in my previous post), you could overwrite the existing value directly, because no type conversion would occur:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
c=put(input(c,mmddyy10.),yymmddn8.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, this would leave the length of the variable at 10, although 8 would be sufficient. To avoid this, you could define a new variable with length 8 and then drop and rename as shown above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 18:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-date-to-YYYYMMDD-date-field/m-p/258326#M49732</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-22T18:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character date to YYYYMMDD date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-date-to-YYYYMMDD-date-field/m-p/258332#M49735</link>
      <description>Thanks Reinhard, I did not know this drop trick. Very helpful.</description>
      <pubDate>Tue, 22 Mar 2016 19:06:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-date-to-YYYYMMDD-date-field/m-p/258332#M49735</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-03-22T19:06:54Z</dc:date>
    </item>
  </channel>
</rss>

