DATA Step, Macro, Functions and more

Report

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Report

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.


Accepted Solutions
Solution
‎05-30-2016 01:24 PM
Super User
Super User
Posts: 7,988

Re: Report

Posted in reply to partha_125

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


All Replies
Solution
‎05-30-2016 01:24 PM
Super User
Super User
Posts: 7,988

Re: Report

Posted in reply to partha_125

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;
New Contributor
Posts: 3

Re: Report

Thanks a lot
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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