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.
I think this is what you are looking for
Determine if a data set exists and conditionally execute additional steps
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.
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.
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
Is that date in a variable in the dataset, or the modification date of the dataset file?
It's a modification date of the dataset file
can we do it?
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.
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: