BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sathya66
Barite | Level 11

Hi All,

our job runs every 20 mins like  8:00,8:20,8:40.9:00 ,9:20 so on

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).

EX:

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

/Input/test/date_2021_8_13/time_06_00/

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

/Input/test/date_2021_8_13/time_06_20/

 

And so on

 

%let time=%sysfunc(time(), hhmm); %put &time;
%let Time_HH   = %scan(&Time.,1,:)            ;
%let Time_MM   = %scan(&Time.,2,:)            ;
%let DateCCYY  = %sysfunc(date(),year4.)      ;
%let Date_MM   = %sysfunc(date(),Month2.)     ;  
%let Date_DD   = %sysfunc(date(),Day2.)       ; 
%let folder= /Input/test/date_&DateCCYY._&Date_MM._&Date_DD./time_&Time_HH._&Time_MM./;

%put &Time_HH &Time_MM &DateCCYY.&Date_MM. &Date_DD.  &folder;
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Here a way using intnx() to align as SAS Datetime value 2 hours back to a 20 minutes boundary.

intnx('dtminute20',datetime(),-6,'b')

  • dtminute20 defines 20 minutes intervals
  • -6 substracts 6 such intervals from the current start value
  • 'b' aligns the datetime value to the beginning of the interval

I've also added picture formats to generate the folder names as you need them.

I've used a data _null_ step because I find that easier to read and debug than calling such functions via %sysfunc().

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 &=path;

PATH=/Input/test/date_2020_12_31/time_23_20

Relevant docu entries:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0syn64amroombn14vrdzksh459w.h... 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0n990vq8gxca6n1vnsracr6jp2c.htm#p0eubpi... 

 

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

It doesn't seem like you have asked a question.

 

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.

--
Paige Miller
Patrick
Opal | Level 21

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? 

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.

sathya66
Barite | Level 11
Thanks for this,
If SAS down for more than 20 mins or so , currently user is running manually (hardcoding the time ). We go with control table.
Tom
Super User Tom
Super User

I think you have two questions here.

First is how to determine the time point you want to use based on the current time.

Second is how to convert that time point into a file/directory name.

 

For the first one it sounds like you want a 2 hour delay and then find the pervious 20 minute interval.  So if it is 8:45 now you want to use 6:40.  If it is 8:35 then you want to use 6:20. 

%let delay='02:00't;
%let interval='00:20't ;
%let now =%sysfunc(datetime());
%let past=%sysevalf(&now -&delay - %sysfunc(mod(&now,&interval)));

Test:

62    %let delay='02:00't;
63    %let interval='00:20't ;
64    %let now =%sysfunc(datetime());
65    %let past=%sysevalf(&now -&delay - %sysfunc(mod(&now,&interval)));
66    %put now =%sysfunc(putn(&now,datetime20.));
now =  13AUG2021:11:50:32
67    %put past=%sysfunc(putn(&past,datetime20.));
past=  13AUG2021:09:40:00

For the second part to get a string in YYYY_MM_DD style you could the YYMMDD format and change the hyphens to underscores.  To get a string in HH_MM your could use the TOD format and change the colon to an underscore:

%let date=%sysfunc(translate(%sysfunc(datepart(&past),yymmdd10.),_,-));
%let time=%sysfunc(translate(%sysfunc(timepart(&past),tod5.),_,:));
%let folder=/Input/test/date_&date/time_&time/ ;

Test:

74    %let date=%sysfunc(translate(%sysfunc(datepart(&past),yymmdd10.),_,-));
75    %let time=%sysfunc(translate(%sysfunc(timepart(&past),tod5.),_,:));
76    %let folder=/Input/test/date_&date/time_&time/ ;
77    %put &=date &=time &=folder;
DATE=2021_08_13 TIME=09_40 FOLDER=/Input/test/date_2021_08_13/time_09_40/
Patrick
Opal | Level 21

Here a way using intnx() to align as SAS Datetime value 2 hours back to a 20 minutes boundary.

intnx('dtminute20',datetime(),-6,'b')

  • dtminute20 defines 20 minutes intervals
  • -6 substracts 6 such intervals from the current start value
  • 'b' aligns the datetime value to the beginning of the interval

I've also added picture formats to generate the folder names as you need them.

I've used a data _null_ step because I find that easier to read and debug than calling such functions via %sysfunc().

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 &=path;

PATH=/Input/test/date_2020_12_31/time_23_20

Relevant docu entries:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0syn64amroombn14vrdzksh459w.h... 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0n990vq8gxca6n1vnsracr6jp2c.htm#p0eubpi... 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1087 views
  • 4 likes
  • 4 in conversation