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-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!

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
  • 2 replies
  • 801 views
  • 1 like
  • 2 in conversation