<?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 datetime in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957738#M373852</link>
    <description>&lt;P&gt;Do your actual values have a time component? I ask because sometimes we have uses of "datetime" values that are all 00:00:00 for time and the problem is a tad bit easier if we don't have to actually process a time component.&lt;/P&gt;
&lt;P&gt;DT below has the desired datetime value.&lt;/P&gt;
&lt;PRE&gt;data example;
  string='31.12.1970 00:00:00';
  date = input(scan(string,1,' '),ddmmyy10.);
  dt = dhms(date,0,0,0);
  format date date9.;
run;&lt;/PRE&gt;
&lt;P&gt;If there is actual time value&lt;/P&gt;
&lt;PRE&gt;data example2;
  string='31.12.1970 01:12:45';
  date = input(scan(string,1,' '),ddmmyy10.);
  time = input(scan(string,2,' '),time.);
  dt = dhms(date,0,0,time);
  format date date9. time time8.;
run;&lt;/PRE&gt;
&lt;P&gt;The DHMS function takes a date, hour, minute and second value to create a datetime. So if the "time" is actually 0 hours, 0 minutes and 0 seconds we can use those and not bother to actually read the time component.&lt;/P&gt;
&lt;P&gt;If a value is already a time value placing it in the seconds position suffices to provide the hours and minutes but you do need the 0 for the hour and minute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jan 2025 22:14:32 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2025-01-30T22:14:32Z</dc:date>
    <item>
      <title>Converting datetime in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957729#M373850</link>
      <description>I want to convert a string „31.12.1970 00:00:00“ to a SAS Date (seconds since 1960) in order to insert it into a sql server table. Is there any easy way to do so?</description>
      <pubDate>Thu, 30 Jan 2025 21:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957729#M373850</guid>
      <dc:creator>jscer</dc:creator>
      <dc:date>2025-01-30T21:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: Converting datetime in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957738#M373852</link>
      <description>&lt;P&gt;Do your actual values have a time component? I ask because sometimes we have uses of "datetime" values that are all 00:00:00 for time and the problem is a tad bit easier if we don't have to actually process a time component.&lt;/P&gt;
&lt;P&gt;DT below has the desired datetime value.&lt;/P&gt;
&lt;PRE&gt;data example;
  string='31.12.1970 00:00:00';
  date = input(scan(string,1,' '),ddmmyy10.);
  dt = dhms(date,0,0,0);
  format date date9.;
run;&lt;/PRE&gt;
&lt;P&gt;If there is actual time value&lt;/P&gt;
&lt;PRE&gt;data example2;
  string='31.12.1970 01:12:45';
  date = input(scan(string,1,' '),ddmmyy10.);
  time = input(scan(string,2,' '),time.);
  dt = dhms(date,0,0,time);
  format date date9. time time8.;
run;&lt;/PRE&gt;
&lt;P&gt;The DHMS function takes a date, hour, minute and second value to create a datetime. So if the "time" is actually 0 hours, 0 minutes and 0 seconds we can use those and not bother to actually read the time component.&lt;/P&gt;
&lt;P&gt;If a value is already a time value placing it in the seconds position suffices to provide the hours and minutes but you do need the 0 for the hour and minute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2025 22:14:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957738#M373852</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-01-30T22:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: Converting datetime in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957739#M373853</link>
      <description>&lt;P&gt;Someone on here will have a slick way to do this, but crudely, you could do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
dtstring="31.12.1970 00:00:00";
dtpart=scan(dtstring,1,' ');
timepart=scan(dtstring,2,' ');
dt_time=dhms(
    mdy(scan(dtpart,2,'.')*1, scan(dtpart,1,'.')*1, scan(dtpart,3,'.')*1),  /* this is the date*/
    scan(timepart,1,':')*1,  /* hour */
    scan(timepart,2,':')*1,  /* minute */
    scan(timepart,3,':')*1  /* second */
    );
format dt_time datetime.;
drop dtpart timepart;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jan 2025 22:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957739#M373853</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-01-30T22:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Converting datetime in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957741#M373854</link>
      <description>&lt;P&gt;The input function only reads what it needs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EXAMPLE;
  STR  = '31.12.1970 00:00:00';
  DATE = input(STRING, ddmmyy10.);
  putlog DATE= date9.;
run;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE id="pre_sasLog_101" class="sasLog" style="background-color: transparent; -webkit-user-select: text; -webkit-user-modify: read-only; -webkit-touch-callout: default; border-top-width: 0px; border-bottom-width: 0px;"&gt;&lt;FONT face="courier new,courier"&gt;DATE=31DEC1970&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2025 22:23:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957741#M373854</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2025-01-30T22:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Converting datetime in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957758#M373855</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options datestyle=dmy;
data EXAMPLE;
  STRING  = '31.12.1970 00:00:00';
  DATE = input(STRING, anydtdtm32.);
  format date e8601dt.;
run; 
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1738289006415.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104158iD9945CD3059FF029/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1738289006415.png" alt="Ksharp_0-1738289006415.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2025 02:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957758#M373855</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-01-31T02:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: Converting datetime in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957770#M373858</link>
      <description>I used this without the final formatting and got my desired number of seconds since 1960. Somehow the proc sql insert won‘t work, because the number, that should be put in my SQLServer Tabel column of type „datetime“, due to a type mismatch.&lt;BR /&gt;&lt;BR /&gt;Is there a difference between the output of datetime() and a number that i get from dhms(mdy(blabla…))?</description>
      <pubDate>Fri, 31 Jan 2025 06:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957770#M373858</guid>
      <dc:creator>jscer</dc:creator>
      <dc:date>2025-01-31T06:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: Converting datetime in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957771#M373859</link>
      <description>&lt;P&gt;If your SAS variable is not formatted as a datetime, the ACCESS module you use to connect to the database does not know that the target should be of type datetime. Apply an appropriate format in SAS.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2025 07:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-datetime-in-SAS/m-p/957771#M373859</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-01-31T07:56:19Z</dc:date>
    </item>
  </channel>
</rss>

