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

Hi,

we have numerous reports which runs on daily, weekly and monthly basis. I want to build a system which keeps track of the reports run. so that if the report especially the daily ones does not run for a couple of days because of various reasons like server unavailability or database unavailabilty. so when the report runs the next time it should be able to catch up the missing days and generate files .

I am planning to acheive this through sas coding.

 

Any detailed input would be helpful.

Regards.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I would personally not do this "catchup" thing myself, you may end up in problems.  Make sure your DB has timestamps otherwise you wont be able to do this.  Drop a directory listing into a dataset, find the last date, then have a do loop between the last date+ 1 and now, and call the report once for each day (note note tested, assumes Windows, database connection, and a load of other things):

%macro Report (day=);
  proc sql;
    connect to db (path...);
    select * from db (select * from yourtable where timestamp=input("&DAY.",date9.));
    disconnect from db;
  quit;
  ods file="S:\Temp\Rob\DAily\ABC_&DAY..txt";
  proc report...;
  run;
%mend Report;

libname daily "S:\Temp\Rob\DAily";
filename tmp pipe 'dir "S:\Temp\Rob\DAily\*.txt" /b';
data dir;
  length fname $100;
  infile tmp dlm="¬";
  input fname $;
  dte=input(scan(fname,2,"_"),yymmdd8.);
  format dte date9.;
run;
proc sort data=dir;
  by descending dte;
run;
data _null_;
  set dir (obs=1);
  do i=dte+1 to today();
    call execute(cats('%Report (day=',put(i,date9.),');'));
  end;
run;

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I would personally not do this "catchup" thing myself, you may end up in problems.  Make sure your DB has timestamps otherwise you wont be able to do this.  Drop a directory listing into a dataset, find the last date, then have a do loop between the last date+ 1 and now, and call the report once for each day (note note tested, assumes Windows, database connection, and a load of other things):

%macro Report (day=);
  proc sql;
    connect to db (path...);
    select * from db (select * from yourtable where timestamp=input("&DAY.",date9.));
    disconnect from db;
  quit;
  ods file="S:\Temp\Rob\DAily\ABC_&DAY..txt";
  proc report...;
  run;
%mend Report;

libname daily "S:\Temp\Rob\DAily";
filename tmp pipe 'dir "S:\Temp\Rob\DAily\*.txt" /b';
data dir;
  length fname $100;
  infile tmp dlm="¬";
  input fname $;
  dte=input(scan(fname,2,"_"),yymmdd8.);
  format dte date9.;
run;
proc sort data=dir;
  by descending dte;
run;
data _null_;
  set dir (obs=1);
  do i=dte+1 to today();
    call execute(cats('%Report (day=',put(i,date9.),');'));
  end;
run;
partha_125
Fluorite | Level 6
Thanks a lot

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1098 views
  • 1 like
  • 2 in conversation