<?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  time macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-time-macro/m-p/761741#M241082</link>
    <description>Thanks for this,&lt;BR /&gt;If SAS down for more than 20 mins or so , currently user is running manually (hardcoding the time ). We go with control table.&lt;BR /&gt;</description>
    <pubDate>Mon, 16 Aug 2021 07:33:36 GMT</pubDate>
    <dc:creator>sathya66</dc:creator>
    <dc:date>2021-08-16T07:33:36Z</dc:date>
    <item>
      <title>SAS  time macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-time-macro/m-p/761434#M240953</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;our job runs every 20 mins like&amp;nbsp; 8:00,8:20,8:40.9:00 ,9:20 so on&lt;/P&gt;
&lt;P&gt;so I need read the file which is in time_XX_XX folder(folder names are like time_06_00, time_06_20,time_06_40 and so on).&lt;/P&gt;
&lt;P&gt;EX:&lt;/P&gt;
&lt;P&gt;If I run a job at 8:00 it should read time_06_00 (2 hrs delay) folder sometimes it can be delayed few secs/mins however we need to read time_06_00 folder&lt;/P&gt;
&lt;P&gt;/Input/test/date_2021_8_13/time_06_00/&lt;/P&gt;
&lt;P&gt;If I run a job at 8:20 it should read time_06_20 (2 hrs delay) folder sometimes it can be delayed few mins however we need to read time_06_20 folder&lt;/P&gt;
&lt;P&gt;/Input/test/date_2021_8_13/time_06_20/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And so on&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let time=%sysfunc(time(), hhmm); %put &amp;amp;time;
%let Time_HH   = %scan(&amp;amp;Time.,1,:)            ;
%let Time_MM   = %scan(&amp;amp;Time.,2,:)            ;
%let DateCCYY  = %sysfunc(date(),year4.)      ;
%let Date_MM   = %sysfunc(date(),Month2.)     ;  
%let Date_DD   = %sysfunc(date(),Day2.)       ; 
%let folder= /Input/test/date_&amp;amp;DateCCYY._&amp;amp;Date_MM._&amp;amp;Date_DD./time_&amp;amp;Time_HH._&amp;amp;Time_MM./;

%put &amp;amp;Time_HH &amp;amp;Time_MM &amp;amp;DateCCYY.&amp;amp;Date_MM. &amp;amp;Date_DD.  &amp;amp;folder;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Aug 2021 14:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-time-macro/m-p/761434#M240953</guid>
      <dc:creator>sathya66</dc:creator>
      <dc:date>2021-08-13T14:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAS  time macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-time-macro/m-p/761436#M240955</link>
      <description>&lt;P&gt;It doesn't seem like you have asked a question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you just want to subtract two hours from macro variable time? Do you need to round to the nearest 20 minutes? What do you need help with? Please explain further.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 15:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-time-macro/m-p/761436#M240955</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-13T15:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS  time macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-time-macro/m-p/761456#M240962</link>
      <description>&lt;P&gt;What happens if SAS is ever down for more than 20 minutes. Can you just skip one of the folders or do you need to do catch-up runs?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's catch-up runs then you'd better go for a control table where you keep track of folders already processed rather than just basing everything on execution datetime.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 15:56:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-time-macro/m-p/761456#M240962</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-08-13T15:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS  time macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-time-macro/m-p/761457#M240963</link>
      <description>&lt;P&gt;I think you have two questions here.&lt;/P&gt;
&lt;P&gt;First is how to determine the time point you want to use based on the current time.&lt;/P&gt;
&lt;P&gt;Second is how to convert that time point into a file/directory name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the first one it sounds like you want a 2 hour delay and then find the pervious 20 minute interval.&amp;nbsp; So if it is 8:45 now you want to use 6:40.&amp;nbsp; If it is 8:35 then you want to use 6:20.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let delay='02:00't;
%let interval='00:20't ;
%let now =%sysfunc(datetime());
%let past=%sysevalf(&amp;amp;now -&amp;amp;delay - %sysfunc(mod(&amp;amp;now,&amp;amp;interval)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Test:&lt;/P&gt;
&lt;PRE&gt;62    %let delay='02:00't;
63    %let interval='00:20't ;
64    %let now =%sysfunc(datetime());
65    %let past=%sysevalf(&amp;amp;now -&amp;amp;delay - %sysfunc(mod(&amp;amp;now,&amp;amp;interval)));
66    %put now =%sysfunc(putn(&amp;amp;now,datetime20.));
now =  13AUG2021:11:50:32
67    %put past=%sysfunc(putn(&amp;amp;past,datetime20.));
past=  13AUG2021:09:40:00
&lt;/PRE&gt;
&lt;P&gt;For the second part to get a string in YYYY_MM_DD style you could the YYMMDD format and change the hyphens to underscores.&amp;nbsp; To get a string in HH_MM your could use the TOD format and change the colon to an underscore:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date=%sysfunc(translate(%sysfunc(datepart(&amp;amp;past),yymmdd10.),_,-));
%let time=%sysfunc(translate(%sysfunc(timepart(&amp;amp;past),tod5.),_,:));
%let folder=/Input/test/date_&amp;amp;date/time_&amp;amp;time/ ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Test:&lt;/P&gt;
&lt;PRE&gt;74    %let date=%sysfunc(translate(%sysfunc(datepart(&amp;amp;past),yymmdd10.),_,-));
75    %let time=%sysfunc(translate(%sysfunc(timepart(&amp;amp;past),tod5.),_,:));
76    %let folder=/Input/test/date_&amp;amp;date/time_&amp;amp;time/ ;
77    %put &amp;amp;=date &amp;amp;=time &amp;amp;=folder;
DATE=2021_08_13 TIME=09_40 FOLDER=/Input/test/date_2021_08_13/time_09_40/
&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Aug 2021 16:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-time-macro/m-p/761457#M240963</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-13T16:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS  time macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-time-macro/m-p/761465#M240968</link>
      <description>&lt;P&gt;Here a way using intnx() to align as SAS Datetime value 2 hours back to a 20 minutes boundary.&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;intnx('dtminute20',datetime(),-6,'b')&lt;/CODE&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;EM&gt;dtminute20&lt;/EM&gt; defines 20 minutes intervals&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;-6&lt;/EM&gt; substracts 6 such intervals from the current start value&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;'b'&lt;/EM&gt; aligns the datetime value to the beginning of the interval&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I've also added picture formats to generate the folder names as you need them.&lt;/P&gt;
&lt;P&gt;I've used a data _null_ step because I find that easier to read and debug than calling such functions via %sysfunc().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  picture time_hh_mm
    low-high = 'time_%0H_%0M' (datatype=datetime)
    ;
  picture date_yyyy_mm_dd
    low-high = 'date_%Y_%0m_%0d' (datatype=datetime)
    ;
run;

data _null_;
/*  dt=datetime();*/
  dt='01jan2021 01:23:07'dt;
  dt_shift=intnx('dtminute20',dt,-6,'b');
  date_folder=put(dt_shift,date_yyyy_mm_dd.);
  time_folder=put(dt_shift,time_hh_mm.);
  call symputx('path',catx('/','/Input/test/date',date_folder,time_folder));
run;

%put &amp;amp;=path;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;PATH=/Input/test/date_2020_12_31/time_23_20&lt;/PRE&gt;
&lt;P&gt;Relevant docu entries:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0syn64amroombn14vrdzksh459w.htm#n1wbckrlffgb8jn15eebgjpqm23c" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0syn64amroombn14vrdzksh459w.htm#n1wbckrlffgb8jn15eebgjpqm23c&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0n990vq8gxca6n1vnsracr6jp2c.htm#p0eubpiv9ngaocn1uatbigc5swi2" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0n990vq8gxca6n1vnsracr6jp2c.htm#p0eubpiv9ngaocn1uatbigc5swi2&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Aug 2021 02:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-time-macro/m-p/761465#M240968</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-08-14T02:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: SAS  time macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-time-macro/m-p/761741#M241082</link>
      <description>Thanks for this,&lt;BR /&gt;If SAS down for more than 20 mins or so , currently user is running manually (hardcoding the time ). We go with control table.&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Aug 2021 07:33:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-time-macro/m-p/761741#M241082</guid>
      <dc:creator>sathya66</dc:creator>
      <dc:date>2021-08-16T07:33:36Z</dc:date>
    </item>
  </channel>
</rss>

