<?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: Difference in time- minutes. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-time-minutes/m-p/951628#M371984</link>
    <description>&lt;P&gt;Your datetime literals in the SQL must be written as datetime literals. I'd also add the TRIMMED modifier to your INTO clause to trim off leading blanks:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let curr_datetime = 22NOV2024:09:23:33;
%let modate = 22NOV2024:05:55:55;

%macro time_diff(curr_datetime, modate);
proc sql noprint;
    select intck('dtsecond', &lt;STRONG&gt;"&amp;amp;modate"dt&lt;/STRONG&gt;, &lt;STRONG&gt;"&amp;amp;curr_datetime"dt&lt;/STRONG&gt;) into :time_diff &lt;STRONG&gt;trimmed&lt;/STRONG&gt;
    from sashelp.cars(obs=1);
  quit;
  %put The time difference is &amp;amp;time_diff seconds;
%mend time_diff;
%time_diff(&amp;amp;curr_datetime.,&amp;amp;modate.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 22 Nov 2024 15:14:19 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2024-11-22T15:14:19Z</dc:date>
    <item>
      <title>Difference in time- minutes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-time-minutes/m-p/951619#M371982</link>
      <description>&lt;P&gt;Need help in calculating difference in time between two macro variables.&lt;/P&gt;&lt;P&gt;Here is what i have:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let curr_datetime = 22NOV2024:09:23:33;
%let modate = 22NOV2024:05:55:55;

%macro time_diff(curr_datetime, modate);
proc sql noprint;
    select intck('second', &amp;amp;modate, &amp;amp;curr_datetime) into :time_diff
    from sashelp.vcalendar;
  quit;
  %put The time difference is &amp;amp;time_diff seconds;
%mend time_diff;
%time_diff(&amp;amp;curr_datetime.,&amp;amp;modate.);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please advise.&lt;/P&gt;&lt;P&gt;Thank You&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2024 14:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-time-minutes/m-p/951619#M371982</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2024-11-22T14:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: Difference in time- minutes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-time-minutes/m-p/951628#M371984</link>
      <description>&lt;P&gt;Your datetime literals in the SQL must be written as datetime literals. I'd also add the TRIMMED modifier to your INTO clause to trim off leading blanks:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let curr_datetime = 22NOV2024:09:23:33;
%let modate = 22NOV2024:05:55:55;

%macro time_diff(curr_datetime, modate);
proc sql noprint;
    select intck('dtsecond', &lt;STRONG&gt;"&amp;amp;modate"dt&lt;/STRONG&gt;, &lt;STRONG&gt;"&amp;amp;curr_datetime"dt&lt;/STRONG&gt;) into :time_diff &lt;STRONG&gt;trimmed&lt;/STRONG&gt;
    from sashelp.cars(obs=1);
  quit;
  %put The time difference is &amp;amp;time_diff seconds;
%mend time_diff;
%time_diff(&amp;amp;curr_datetime.,&amp;amp;modate.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Nov 2024 15:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-time-minutes/m-p/951628#M371984</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-11-22T15:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Difference in time- minutes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-time-minutes/m-p/951645#M371985</link>
      <description>&lt;P&gt;You don't need to use a SQL step for the calculation, you can use the %SYSFUNC macro function to call INTCK, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    %let curr_datetime = 22NOV2024:09:23:33;
2    %let modate = 22NOV2024:05:55:55;
3
4    %put The time difference is: %sysfunc(intck(minutes,"&amp;amp;curr_datetime"dt,"&amp;amp;modate"dt)) minutes. ;
The time difference is: -208 minutes.
&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Nov 2024 15:30:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-time-minutes/m-p/951645#M371985</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-11-22T15:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: Difference in time- minutes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-time-minutes/m-p/951692#M371993</link>
      <description>&lt;P&gt;That macro would work if you gave it actual datetime values instead of the strings you actually have.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%time_diff("&amp;amp;curr_datetime"dt,"&amp;amp;modate"dt);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the macro is way too complicated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro time_diff(curr_datetime, modate);
%local time_diff;
%let time_diff=%sysfunc(intck(second, &amp;amp;modate, &amp;amp;curr_datetime));
%put The time difference is &amp;amp;time_diff seconds;
%mend time_diff;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you actually want the time in some other interval then you might add another parameter to the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro time_diff(curr_datetime, modate, interval);
%local time_diff;
%if 0=%length(&amp;amp;interval) %then %let interval=second;
%let time_diff=%sysfunc(intck(&amp;amp;interval, &amp;amp;modate, &amp;amp;curr_datetime));
%put The time difference is &amp;amp;time_diff &amp;amp;interval.s;
%mend time_diff;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you could get the difference in minutes or hours.&lt;/P&gt;
&lt;PRE&gt;1    %macro time_diff(curr_datetime, modate, interval);
2    %local time_diff;
3    %if 0=%length(&amp;amp;interval) %then %let interval=second;
4    %let time_diff=%sysfunc(intck(&amp;amp;interval, &amp;amp;modate, &amp;amp;curr_datetime));
5    %put The time difference is &amp;amp;time_diff &amp;amp;interval.s;
6    %mend time_diff;
7
8    %let curr_datetime = 22NOV2024:09:23:33;
9    %let modate = 22NOV2024:05:55:55;
10   %time_diff("&amp;amp;curr_datetime"dt,"&amp;amp;modate"dt);
The time difference is 12458 seconds
11   %time_diff("&amp;amp;curr_datetime"dt,"&amp;amp;modate"dt,minute);
The time difference is 208 minutes
12   %time_diff("&amp;amp;curr_datetime"dt,"&amp;amp;modate"dt,hour);
The time difference is 4 hours
13   %time_diff("&amp;amp;curr_datetime"dt,"&amp;amp;modate"dt,dtday);
The time difference is 0 dtdays
&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Nov 2024 00:35:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-time-minutes/m-p/951692#M371993</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-23T00:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: Difference in time- minutes.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-time-minutes/m-p/951699#M371998</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let curr_datetime = 22NOV2024:09:23:33;
%let modate = 22NOV2024:05:55:55;



%let time_diff=%sysevalf("&amp;amp;curr_datetime"dt-"&amp;amp;modate"dt);
%put The time difference is &amp;amp;time_diff seconds;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Nov 2024 07:17:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-time-minutes/m-p/951699#M371998</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-11-23T07:17:52Z</dc:date>
    </item>
  </channel>
</rss>

