BookmarkSubscribeRSS Feed
ankit1may
Calcite | Level 5

Hi,

 

I have one dataset which gets updated everyday in the server. I have a batch job reading this. The issue is whenever this dataset does not exists, my batch jobs throws error and the code does not run for that day.

Can someone please help me with the code to keep checking if this dataset exists and run the remaining part of the code once it is available in the server in a single day?

 

Thank you for helping me out.

 

7 REPLIES 7
ankit1may
Calcite | Level 5

Thank you for your reply.

I have tried this. It only checks once. What I am looking for is , a code to check if datasets exists, if not then wait for 1 hour. After 1 hour, it should check if dataset exists or not again, and if the dataset available, then run the code from that junction.

Kurt_Bremser
Super User
data _null_;
do while (not fileexist("filename"));
  sleep(3600,1);
end;
run;

This step will run until the file is present. You might add code that terminates the program abnormally (abort abend) if too many iterations are done.

Ranny
Obsidian | Level 7

I have SAS dataset in -

Libname XYZ "/unix/mypath/project/202012";

SAS dataset - Project_dataset.sas7bdat  with yesterday's date12/07/2020

 

what I want is - If above dataset is available with today's date 12/08/2020 then move to the next step otherwise wait until today's file is available.

 

How can we do this?

 

Thank you,

Renny  

 

Ranny
Obsidian | Level 7

It's a modification date of the dataset file

 

can we do it?

Kurt_Bremser
Super User

See this macro code:

libname XYZ "/unix/mypath/project/202012";

%macro wait_till_ready;
%local today modate x;
%let today = %sysfunc(today());
proc sql noprint;
select datepart(modate) into :modate
from dictionary.tables
where libname = "XYZ" and memname = "PROJECT_DATASET"
;
quit;
%if &sqlobs = 0
%then %do;
  %put "Dataset does not exist!";
  %abort cancel;
%end;
%do %while (&modate ne &today);
  %let x = %sysfunc(sleep(60,1)); /* wait a minute */
  proc sql noprint;
  select datepart(modate) into :modate
  from dictionary.tables
  where libname = "XYZ" and memname = "PROJECT_DATASET"
  ;
  quit;
  %if %sysfunc(today()) gt &today
  %then %do;
    %put "No new data for this day!";
    %abort cancel;
  %end;
%end;
%mend;

The macro will check first if the dataset exists; if not, a message is issued and an error condition raised, and in a non-interactive session (batch), the session is terminated.

It retrieves the modification timestamp from DICTIONARY.TABLES, extracts the date, and compares that to the rundate of the job. If the dates don't match, it waits for a minute,

If the current date exceeds the rundate, a message is issued and the job/submit terminated abnormally.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 7 replies
  • 2451 views
  • 1 like
  • 4 in conversation