<?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 charater date to sas date formats in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/charater-date-to-sas-date-formats/m-p/538901#M148404</link>
    <description>&lt;P&gt;&amp;nbsp;hi all i am looking to convert the non homogeneous character date to date format. following is the data examples of the dates in character form. 14/2/2019 6:37 PM 5/2/2019 14:05 2/2/2019 12:20 1/2/2019 15:00 2/2/2019 12:47 11/2/2019 12:16 19/2/2019 3:41 PM 20/2/2019 10:59 AM 13/2/2019 2:03 PM so if i use the following formula then the dates with AM/PM is been converted input(Opened_date,anydtdte10.) format new_date date10. ; &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Feb 2019 08:14:50 GMT</pubDate>
    <dc:creator>anirudhs</dc:creator>
    <dc:date>2019-02-27T08:14:50Z</dc:date>
    <item>
      <title>charater date to sas date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/charater-date-to-sas-date-formats/m-p/538901#M148404</link>
      <description>&lt;P&gt;&amp;nbsp;hi all i am looking to convert the non homogeneous character date to date format. following is the data examples of the dates in character form. 14/2/2019 6:37 PM 5/2/2019 14:05 2/2/2019 12:20 1/2/2019 15:00 2/2/2019 12:47 11/2/2019 12:16 19/2/2019 3:41 PM 20/2/2019 10:59 AM 13/2/2019 2:03 PM so if i use the following formula then the dates with AM/PM is been converted input(Opened_date,anydtdte10.) format new_date date10. ; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 08:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/charater-date-to-sas-date-formats/m-p/538901#M148404</guid>
      <dc:creator>anirudhs</dc:creator>
      <dc:date>2019-02-27T08:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: charater date to sas date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/charater-date-to-sas-date-formats/m-p/538905#M148406</link>
      <description>&lt;P&gt;Simplest method I can think of is to standardise your data first off.&amp;nbsp; So - and you have not provided any test data in the form of a datastep, so nothing to work with - if you have a text string:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;14/2/2019 6:37 PM&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;First, separate out the three parts, so you have a date, a time, and possibly an indicator.&amp;nbsp; Then if indicator is PM, add 12h to time.&amp;nbsp; Then you can combine date and time to get date/time.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;data want;
  instr="14/2/2019 6:37 PM";
  dte=input(scan(instr,1," "),ddmmyy10.);
  time=input(scan(instr,2," "),time5.);
  indic=scan(instr,3," ");
  if strip(upcase(indic))="PM" then time=time+"12:00"t;
  wantdt=dhms(dte,hour(time),minute(time),0);
  format dte date9. time time5. wantdt datetime.;
run;
  &lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 09:16:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/charater-date-to-sas-date-formats/m-p/538905#M148406</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-27T09:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: charater date to sas date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/charater-date-to-sas-date-formats/m-p/538915#M148408</link>
      <description>&lt;P&gt;now any other solution where this can be done in one formula&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 10:03:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/charater-date-to-sas-date-formats/m-p/538915#M148408</guid>
      <dc:creator>anirudhs</dc:creator>
      <dc:date>2019-02-27T10:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: charater date to sas date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/charater-date-to-sas-date-formats/m-p/538916#M148409</link>
      <description>&lt;P&gt;I only split it up to clearly show the process, just combine the statements:&lt;/P&gt;
&lt;PRE&gt;data want;
  instr="14/2/2019 6:37 PM";
  wantdt=dhms(input(scan(instr,1," "),ddmmyy10.),
              hour(input(scan(instr,2," "),time5.)+ifn(scan(instr,3," ")="PM","12:00"t,0)),
              minute(input(scan(instr,2," "),time5.)+ifn(scan(instr,3," ")="PM","12:00"t,0)),
              0);
  format wantdt datetime.;
run;&lt;/PRE&gt;
&lt;P&gt;Or just run an if statement on the data and add in the missing AM/PM part.&amp;nbsp; The problem is you have data which does not conform to a structure, therefore you need to apply the rest of the structure.&amp;nbsp; If it was me, I would look at my import agreement, see the data did not match and then reject the data for being non-compliant.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 10:12:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/charater-date-to-sas-date-formats/m-p/538916#M148409</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-27T10:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: charater date to sas date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/charater-date-to-sas-date-formats/m-p/538917#M148410</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date$20.;
newdate=input(prxchange('s/(\d+\/)(\d+\/)(\d+)/$2$1$3/',-1,strip(date)),MDYAMPM20.);
datepart=datepart(newdate);
format newdate datetime20. datepart date9.;
cards;
14/2/2019 6:37 PM
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Feb 2019 10:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/charater-date-to-sas-date-formats/m-p/538917#M148410</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-02-27T10:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: charater date to sas date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/charater-date-to-sas-date-formats/m-p/538918#M148411</link>
      <description>&lt;P&gt;Using the ANYDTDTE or ANYDTDTM should just work as expected, see example below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile cards;
  input someDate_c $32.;
  someDate = input(someDate_c, anydtdte32.);
  someDateTime = input(someDate_c, anydtdtm32.);
  format
    someDate date9.
    someDateTime datetime19.
  ;
cards4;
14/2/2019 6:37 PM
5/2/2019 14:05
2/2/2019 12:20
1/2/2019 15:00
2/2/2019 12:47
11/2/2019 12:16
19/2/2019 3:41 PM
20/2/2019 10:59 AM
13/2/2019 2:03 PM
;;;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Feb 2019 10:22:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/charater-date-to-sas-date-formats/m-p/538918#M148411</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2019-02-27T10:22:42Z</dc:date>
    </item>
  </channel>
</rss>

