<?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: Problem when converting individual day month year time into datetime in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-when-converting-individual-day-month-year-time-into/m-p/499821#M133043</link>
    <description>&lt;P&gt;Maxim 2: read the log.&lt;/P&gt;
&lt;P&gt;newdatetime is unititialized because you used dataset orifile, and not dataset converttodate.&lt;/P&gt;</description>
    <pubDate>Fri, 28 Sep 2018 09:37:32 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-09-28T09:37:32Z</dc:date>
    <item>
      <title>Problem when converting individual day month year time into datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-when-converting-individual-day-month-year-time-into/m-p/499428#M132904</link>
      <description>&lt;P&gt;I have a data where it has individual column for:&lt;/P&gt;&lt;P&gt;Day, Month, Year, and time.&lt;/P&gt;&lt;P&gt;For time, the source data is 0900 for 9 o clock and weirdly, they have 10000 value.&lt;/P&gt;&lt;P&gt;When formatting that, it can be converted into 10:00. But when i convert it into datetime, it gave warning:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;NOTE: Invalid argument to function INPUT at line 45 column 16.&lt;BR /&gt;year=2014 month=January transformer=T1 Day=Wednesday Date=1 Time=10:00:00&amp;nbsp; numMonth=1 sasdate=01JAN2014 newdatetime=. _ERROR_=1 _N_=39&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are my codes:&lt;/P&gt;&lt;PRE&gt;data converttodate;
        set finaltestone;
            if month = 'January' then numMonth = 1;
            if month = 'February' then numMonth = 2;
            if month = 'March' then numMonth = 3;
            if month = 'April' then numMonth = 4;
            if month = 'May' then numMonth = 5;
            if month = 'June' then numMonth = 6;
            if month = 'July' then numMonth = 7;
            if month = 'August' then numMonth = 8;
            if month = 'September' then numMonth = 9;
            if month = 'October' then numMonth = 10;
            if month = 'November' then numMonth = 11;
            if month = 'December' then numMonth = 12;
            sasdate=mdy(numMonth,date,year);
              format sasdate date9.;
/*            preptime = substr(time,1,4);*/
            format time time.;
            attrib newdatetime format=datetime19.;
            newdatetime=input(put(sasdate,date9.)||put(time,time.),datetime.);
        run;    &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Weirdly, the when the time is 10:00, it will never be able to produce datetime and hence prompting warning in the log for newdatetime.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know what could be the cause of it?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 10:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-when-converting-individual-day-month-year-time-into/m-p/499428#M132904</guid>
      <dc:creator>WorkingMan</dc:creator>
      <dc:date>2018-09-27T10:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Problem when converting individual day month year time into datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-when-converting-individual-day-month-year-time-into/m-p/499430#M132906</link>
      <description>&lt;P&gt;To do the conversion with the datetime informat, you need a colon between the date and the time, e.g.:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newdatetime=input(put(sasdate,date9.)||':'||put(time,time.),datetime.);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or you can use the dhms function:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newdatetime=dhms(sasdate,hour(time),minute(time),second(time));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Date values are the number of days since 01JAN1960. Datetimes are the number of seconds since 01JAN1960:00:00:00. So another possibility is to turn the number of days into seconds and add it to the time:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newdatetime=sasdate*24*60*60+time;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Sep 2018 10:41:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-when-converting-individual-day-month-year-time-into/m-p/499430#M132906</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-09-27T10:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: Problem when converting individual day month year time into datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-when-converting-individual-day-month-year-time-into/m-p/499435#M132911</link>
      <description>&lt;P&gt;Use an informat for the month conversion, and your code will become much cleaner:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input year month :$10. date time :time8.;
format time time8.;
cards;
2014 January 1 10:00:00
;
run;

proc format;
invalue inmonth
  'January' = 1
  'February' = 2
  'March' = 3
  'April' = 4
  'May' = 5
  'June' = 6
  'July' = 7
  'August' = 8
  'September' = 9
  'October' = 10
  'November' = 11
  'December' = 12
;
run;

data want;
set have;
format newdatetime datetime19.;
newdate = mdy(input(month,inmonth.),date,year);
newdatetime = dhms(newdate,0,0,time);
drop newdate;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Sep 2018 11:01:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-when-converting-individual-day-month-year-time-into/m-p/499435#M132911</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-27T11:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problem when converting individual day month year time into datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-when-converting-individual-day-month-year-time-into/m-p/499820#M133042</link>
      <description>&lt;P&gt;After converting to newdatetime, i then tried to use it in a new data step but the datetime will never be displayed properly again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue inmonth
  'January' = 1
  'February' = 2
  'March' = 3
  'April' = 4
  'May' = 5
  'June' = 6
  'July' = 7
  'August' = 8
  'September' = 9
  'October' = 10
  'November' = 11
  'December' = 12
;
run;

data converttodate;
		set finaltestone;
format newdatetime datetime19.;
newdate = mdy(input(month,inmonth.),date,year);
newdatetime = dhms(newdate,0,0,time);
drop newdate;
run;	
					
					
					
data work.finaltesthash;
set orifile;
  length excp_code $50;
  attrib station length=$10; 
attrib voltage length=$10; 
attrib year length=8;
attrib month length=$20;
attrib transformer length=$10;	
attrib newdatetime length=8 format=datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all data under newdatetime became . in work.finaltesthash. It was displaying properly in work.converttodate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone can help me with this?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 09:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-when-converting-individual-day-month-year-time-into/m-p/499820#M133042</guid>
      <dc:creator>WorkingMan</dc:creator>
      <dc:date>2018-09-28T09:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Problem when converting individual day month year time into datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-when-converting-individual-day-month-year-time-into/m-p/499821#M133043</link>
      <description>&lt;P&gt;Maxim 2: read the log.&lt;/P&gt;
&lt;P&gt;newdatetime is unititialized because you used dataset orifile, and not dataset converttodate.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 09:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-when-converting-individual-day-month-year-time-into/m-p/499821#M133043</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-28T09:37:32Z</dc:date>
    </item>
  </channel>
</rss>

