BookmarkSubscribeRSS Feed
santosh_pat69
Quartz | Level 8

Hi All ...

I am trying to execute a Data Step based on the availability of a signal file.

The  SAS Data Step  should execute after the file is available at a location, the SAS program should check the availablity of file for every 10-15 and for Max time of 3 hours and if the file is available then execute the DATASTEP.

The SAS programs will be called in Cron's

Please suggest me on this.

/*DATE VARIABLES FOR THE CURRENT ORPHAN RUN...BASED ON THE SIGNAL FILE*/

Data _Null_;

  Rept_date= INTNX('DAY',"&SYSDATE."d,0);

  Mnth=Month(Rept_date);

  Year=Year(Rept_date);

  Days=Day(Rept_date);

  if Mnth<=9 Then

  do;

  Mnth_N=Put(Mnth,Z2.);

  End;

  Else  Mnth_N=Mnth;

  if Days<=9 Then

  do;

  Days_N=Put(Days,Z2.);

  End;

  Else  Days_N=Days;

  Put  Days_N;

  NewDte= Compress(Cats(Year,Mnth_N,Days_N),'/');

  Call Symput ('New_dte',Newdte);

Run;

%put Days====>&new_dte.;

%LET myfilerf=<"FILE PATH........">;

%PUT File=====>>> &myfilerf.;

%LET fname= %trim(SALES_&new_Dte.).txt;

%PUT Filename=====>>> &fname.;

%let Entity= %scan(&myfilerf.,-1); /*Name of the Entity or region for SALES extracted from the File path */

%put Entity======>> &Entity.;

%global counter max;

%let counter=0;

%let max=60; /* Minutes To Check */

options Nomlogic Nomprint Nosymbolgen;

******************************************************************************;

*** RUN JOB ******************************************************************;

******************************************************************************;

%MACRO FILE_WAIT();

  %if (%sysfunc(fileexist(&myfilerf.\&fname.))=1 )% then

  %do;

  %PUT NOTE: "SIGNAL FILES EXISTS, ORPHAN DATA PROCESSING....";

  *INCLUDE THE PROGRAM TO BE EXECUTED IF THE ABOVE CONDTION IS TRUE;

  %end; /*1*/

  %else

  %do;

  %PUT WARNING: WAITING ORPHAN SIGNAL FILES: &myfilerf.\&fname.;

  %do %until (%sysfunc(fileexist(&myfilerf.\&fname.))=1 or (&counter+0 > &max+0));

  Data _Null_;

  Sleep= SLEEP(5,1);

  Run;

  %put MAX====>>>  &max.;

  %let counter=%eval(&counter.+1);

  %put COUNTER===>>>>> &counter.;

  %if &counter+0 > &max+0 %then

  %goto EXIT;

  %if (%sysfunc(fileexist(&myfilerf.\&fname.))=1 ) %then

  %do;

  %put Note: Orphan File Processing...;

  %end;

  *2;

  %end;

  *3;

  *** Stop program if time out ***;

  %end;

  %EXIT:

%mend FILE_WAIT;

%FILE_WAIT();

6 REPLIES 6
LinusH
Tourmaline | Level 20

What is your actual question?

You seems to be on your way of doing the "if file exists read it" logic.

The rerun stuff should be handled by a scheduler.

Data never sleeps
SASKiwi
PROC Star

Many schedulers do what you are attempting to do in SAS - use the existence of a file as a trigger. Does your organisation have such as scheduler? SAS's OEM scheduler LSF provides this capability.

santosh_pat69
Quartz | Level 8

Hi Kurt...

Thank you !!!

We do not use SAS OEM Scheduler, LSF

I would like to handle everything using a Base SAS Code. As the files are available only after the ETL jobs are sucessfully completed.

Please suggest.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Plus one to SASKiwi there.  The process for importing/or putting the file in a location should trigger the SAS job, or be part of the import process.  The SAS program shouldn't be hanging around waiting for a file to appear, its just a waste of resource for what is essentially a process task.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 1387 views
  • 0 likes
  • 5 in conversation