Desktop productivity for business analysts and programmers

To execute SAS Data Step 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.

Reply
Contributor
Posts: 66

To execute SAS Data Step 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.

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();

Esteemed Advisor
Posts: 5,198

Re: To execute SAS Data Step 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.

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
Esteemed Advisor
Posts: 6,646

Re: To execute SAS Data Step 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.

Have your SAS program check with the fileexist function (what you already do), delete or rename the file after processing, and use the servers cron functionality to run the program periodically.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Respected Advisor
Posts: 3,062

Re: To execute SAS Data Step 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.

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.

Contributor
Posts: 66

Re: To execute SAS Data Step 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.

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.

Esteemed Advisor
Posts: 6,646

Re: To execute SAS Data Step 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.

Please provide:

Operating system of the SAS server?

Scheduling system used for ETL jobs?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: To execute SAS Data Step 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.

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.

Ask a Question
Discussion stats
  • 6 replies
  • 405 views
  • 0 likes
  • 5 in conversation