<?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 converting multiple character variables with different formats to a SAS time variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/converting-multiple-character-variables-with-different-formats/m-p/549126#M152333</link>
    <description>&lt;P&gt;I have a SAS dataset with three date variables (all character, $10) that I am trying to convert to SAS date variables using SAS 9.4. The first two (initialvisitdate and birthdate) are in the MM/DD/YY character format and the third (conceptiondate) has some observations in the MM/DD/YY format and some in the MM/DD/YYYY format. This is the code that I have been trying (with various date formats in place of 'anydtdte10.'):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;set xxxx.xxxxxxxxxx;&lt;/P&gt;&lt;P&gt;inivisitdt = INPUT(initialvisitdate, anydtdte10.); &amp;nbsp;/* &amp;nbsp;I have tried MMDDYY8. &amp;nbsp;MMDDYY. etc &amp;nbsp; */&lt;BR /&gt;birthdt = INPUT(birthdate, anydtdte10.);&lt;BR /&gt;conceivedt = INPUT(conceptiondate, anydtdte10.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;format inivisitdt birthdt conceivedt date9.;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 'conceptiondate' variable converts correctly from the 2 character formats described above, but only one observation for the initialvisitdate converted (observation 120 out of 289) - the rest are missing (.) and only 2 observations for the birthdate converted. There doesn't appear to be anything different for these 3 observations. There are no error or warning codes in the log. How can I convert all three of these variables?&lt;/P&gt;</description>
    <pubDate>Sun, 07 Apr 2019 20:04:14 GMT</pubDate>
    <dc:creator>mrprerost</dc:creator>
    <dc:date>2019-04-07T20:04:14Z</dc:date>
    <item>
      <title>converting multiple character variables with different formats to a SAS time variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-multiple-character-variables-with-different-formats/m-p/549126#M152333</link>
      <description>&lt;P&gt;I have a SAS dataset with three date variables (all character, $10) that I am trying to convert to SAS date variables using SAS 9.4. The first two (initialvisitdate and birthdate) are in the MM/DD/YY character format and the third (conceptiondate) has some observations in the MM/DD/YY format and some in the MM/DD/YYYY format. This is the code that I have been trying (with various date formats in place of 'anydtdte10.'):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;set xxxx.xxxxxxxxxx;&lt;/P&gt;&lt;P&gt;inivisitdt = INPUT(initialvisitdate, anydtdte10.); &amp;nbsp;/* &amp;nbsp;I have tried MMDDYY8. &amp;nbsp;MMDDYY. etc &amp;nbsp; */&lt;BR /&gt;birthdt = INPUT(birthdate, anydtdte10.);&lt;BR /&gt;conceivedt = INPUT(conceptiondate, anydtdte10.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;format inivisitdt birthdt conceivedt date9.;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 'conceptiondate' variable converts correctly from the 2 character formats described above, but only one observation for the initialvisitdate converted (observation 120 out of 289) - the rest are missing (.) and only 2 observations for the birthdate converted. There doesn't appear to be anything different for these 3 observations. There are no error or warning codes in the log. How can I convert all three of these variables?&lt;/P&gt;</description>
      <pubDate>Sun, 07 Apr 2019 20:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-multiple-character-variables-with-different-formats/m-p/549126#M152333</guid>
      <dc:creator>mrprerost</dc:creator>
      <dc:date>2019-04-07T20:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: converting multiple character variables with different formats to a SAS time variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-multiple-character-variables-with-different-formats/m-p/549132#M152336</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;There doesn't appear to be anything different&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the result is different then the input is different.&lt;/P&gt;
&lt;P&gt;You have to find the difference to fix the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe some non printable characters such as tab?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The can be spotted using the notprint() function.&lt;/P&gt;
&lt;P&gt;Another way to see rogue characters is to print the string using the $hex. format and look for values outside of the 2F-39 range (and 20 for space).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Apr 2019 21:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-multiple-character-variables-with-different-formats/m-p/549132#M152336</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-04-07T21:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: converting multiple character variables with different formats to a SAS time variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-multiple-character-variables-with-different-formats/m-p/549176#M152361</link>
      <description>&lt;P&gt;If you know the values are in MDY order why not use MMDDYY informat?&lt;/P&gt;
&lt;P&gt;Are you sure your values don't have leading spaces?&amp;nbsp; SAS will not normally display those in the log but they can really mess up the INPUT() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input str $char15.;
  date=input(str,mmddyy10.);
  format str $quote. date mmddyy10.;
cards;
1/3/19
10/23/2018
 10/23/2019
  10/23/2019
   10/23/2019
    10/23/2019
     10/23/2019
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    str                        date

 1     "1/3/19"             01/03/2019
 2     "10/23/2018"         10/23/2018
 3     " 10/23/2019"                 .
 4     "  10/23/2019"       10/23/2020
 5     "   10/23/2019"      10/23/2002
 6     "    10/23/2019"              .
 7     "     10/23/2019"             .
&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Apr 2019 05:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-multiple-character-variables-with-different-formats/m-p/549176#M152361</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-08T05:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: converting multiple character variables with different formats to a SAS time variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-multiple-character-variables-with-different-formats/m-p/549305#M152393</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;If you know the values are in MDY order why not use MMDDYY informat?&lt;/P&gt;
&lt;P&gt;Are you sure your values don't have leading spaces?&amp;nbsp; SAS will not normally display those in the log but they can really mess up the INPUT() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input str $char15.;
  date=input(str,mmddyy10.);
  format str $quote. date mmddyy10.;
cards;
1/3/19
10/23/2018
 10/23/2019
  10/23/2019
   10/23/2019
    10/23/2019
     10/23/2019
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    str                        date

 1     "1/3/19"             01/03/2019
 2     "10/23/2018"         10/23/2018
 3     " 10/23/2019"                 .
 4     "  10/23/2019"       10/23/2020
 5     "   10/23/2019"      10/23/2002
 6     "    10/23/2019"              .
 7     "     10/23/2019"             .
&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But are easily fixed if leading:&lt;/P&gt;
&lt;PRE&gt;data test;
  input str $char15.;
  date=input(&lt;STRONG&gt;left(str)&lt;/STRONG&gt;,mmddyy10.);
  format str $quote. date mmddyy10.;
cards;
1/3/19
10-23-2018
 10.23.2019
  10/23/2019
   10/23/2019
    10/23/2019
     10/23/2019
;&lt;/PRE&gt;
&lt;P&gt;Note that the format will also use a number of other delimiters than / just fine.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 15:15:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-multiple-character-variables-with-different-formats/m-p/549305#M152393</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-08T15:15:21Z</dc:date>
    </item>
  </channel>
</rss>

