<?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: SAS code to extract the hours from current time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945206#M370323</link>
    <description>&lt;P&gt;Thanks all..I slightly tweeked the code and it worked fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;filename fname 'C:\test.txt';

data want ;
  fid = fopen('fname');
  if fid then do ;
    flm = finfo(fid,'Last Modified');
    lm=input(flm,anydtdtm60.);
  end;
  else put 'Cannot openfile';

  *age of the file, in seconds ;
  dur=datetime() -lm ;
dur_hour=hour(dur);

  format lm datetime18. dur time. ;
run;

proc print data=want;
run;&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 25 Sep 2024 14:46:57 GMT</pubDate>
    <dc:creator>freshstarter</dc:creator>
    <dc:date>2024-09-25T14:46:57Z</dc:date>
    <item>
      <title>SAS code to extract the hours from current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945176#M370312</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a requirement to extract the time ( i.e hours ) based on current time and last modofied date and time of a file. I have written a code to extract the last modified time which output as '01 January 2024&amp;nbsp; 16:08:04'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to derive the hours ( i.e Current timestamp - 01 January 2024 16:08:01 ) in a SAS code&amp;nbsp; ? Please help me out.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 10:42:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945176#M370312</guid>
      <dc:creator>freshstarter</dc:creator>
      <dc:date>2024-09-25T10:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to extract the hours from current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945182#M370314</link>
      <description>&lt;P&gt;Show us your code &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 11:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945182#M370314</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2024-09-25T11:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to extract the hours from current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945196#M370317</link>
      <description>&lt;P&gt;filename fname 'C:test.txt';&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;fid = fopen('fname');&lt;/P&gt;
&lt;P&gt;if fid then dol&lt;/P&gt;
&lt;P&gt;flm = finfo(fid,'Last Modified');&lt;/P&gt;
&lt;P&gt;lm=input(flm,datetime18.);&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else put 'Cannot openfile';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let timer_start = %sysfunc (%flm);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;dur=datetime() - &amp;amp;timer_start ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But there are erros in the code, which Im looking to resolve.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 13:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945196#M370317</guid>
      <dc:creator>freshstarter</dc:creator>
      <dc:date>2024-09-25T13:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to extract the hours from current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945198#M370319</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462296"&gt;@freshstarter&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have written a code to extract the last modified time which output as '01 January 2024&amp;nbsp; 16:08:04'.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is this value above stored in a text (character) variable or a numeric variable? Use PROC CONTENTS (or similar) to look it up.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 13:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945198#M370319</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-25T13:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to extract the hours from current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945203#M370320</link>
      <description>&lt;P&gt;THe value stored in a char data type. Im trying to change to proper format and then subracting with the current time. But the code didnot help&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 14:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945203#M370320</guid>
      <dc:creator>freshstarter</dc:creator>
      <dc:date>2024-09-25T14:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to extract the hours from current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945204#M370321</link>
      <description>&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    dt='01 January 2024  16:08:04';
    dt_numeric=input(dt,anydtdtm60.);
    hour=hour(dt_numeric);
    format dt_numeric datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Sep 2024 14:13:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945204#M370321</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-25T14:13:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to extract the hours from current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945205#M370322</link>
      <description>&lt;P&gt;Your main code looks close.&amp;nbsp; You're missing a \ in the file name, should be C:\test.txt.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need to use the macro language, and this bit doesn't make sense to me:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let timer_start = %sysfunc (%flm);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use the DATETIME() function in your first DATA step, and do the subtraction in that step to calculate the age of a file (in seconds), like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename fname 'C:\test.txt';

data want ;
  fid = fopen('fname');
  if fid then do ;
    flm = finfo(fid,'Last Modified');
    lm=input(flm,datetime18.);
  end;
  else put 'Cannot openfile';

  *age of the file, in seconds ;
  dur=datetime() -lm ;

  format lm datetime18. dur time.;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Sep 2024 14:19:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945205#M370322</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-09-25T14:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to extract the hours from current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945206#M370323</link>
      <description>&lt;P&gt;Thanks all..I slightly tweeked the code and it worked fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;filename fname 'C:\test.txt';

data want ;
  fid = fopen('fname');
  if fid then do ;
    flm = finfo(fid,'Last Modified');
    lm=input(flm,anydtdtm60.);
  end;
  else put 'Cannot openfile';

  *age of the file, in seconds ;
  dur=datetime() -lm ;
dur_hour=hour(dur);

  format lm datetime18. dur time. ;
run;

proc print data=want;
run;&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 25 Sep 2024 14:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945206#M370323</guid>
      <dc:creator>freshstarter</dc:creator>
      <dc:date>2024-09-25T14:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to extract the hours from current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945208#M370325</link>
      <description>&lt;P&gt;Note that the format of the strings returned by FINFO() depend on your language settings.&amp;nbsp; I have found the using NLDATM informat works consistently.&amp;nbsp; Also the format of the strings used to specify the information to return depends on the language setting.&amp;nbsp; You can use FOPTNAME() to fix that.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;lastmod = input(finfo(fid,foptname(fid, 5)), nldatm100.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To see this in action check out&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/dirtree.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also the DATETIME format has a bug and you should not use DATETIME18. Even though that should be enough room to include 4 digit years it will not.&amp;nbsp; So either use DATETIME19. (four digit years) or DATETIME16. (two digit years).&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 15:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945208#M370325</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-25T15:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code to extract the hours from current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945229#M370329</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;Note that the format of the strings returned by FINFO() depend on your language settings.&amp;nbsp; I have found the using NLDATM informat works consistently.&amp;nbsp; Also the format of the strings used to specify the information to return depends on the language setting.&amp;nbsp; You can use FOPTNAME() to fix that.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;lastmod = input(finfo(fid,foptname(fid, 5)), nldatm100.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To see this in action check out&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/dirtree.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also the DATETIME format has a bug and you should not use DATETIME18. Even though that should be enough room to include 4 digit years it will not.&amp;nbsp; So either use DATETIME19. (four digit years) or DATETIME16. (two digit years).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That DATETIME18. format bug drives me crazy every time I re-encounter it.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 16:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-to-extract-the-hours-from-current-time/m-p/945229#M370329</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-09-25T16:41:45Z</dc:date>
    </item>
  </channel>
</rss>

