Use log file macro to keep track of jobs

Hi Team
I'm trying to write a macro in sas, that will log the time a job has been run its name and start and end time.
It then should append this information to a log table in SAS

Who is Participating?
Aloysius LowConnect With a Mentor Commented:
how are you triggering the job currently?

what you could do is to write a wrapper sas script which will log the start time of the job and the time the job ends and then write a record to the log table

e.g. (just to give you an idea, actual implementation depends on how you are currently executing the sas code and any other requirements)

  %let starttime = datetime();
  %include "&filename";
  %let endtime = datetime();

  data job_details;
    starttime = &starttime;
    endtime = &endtime;
    jobname = "&filename";

  proc append base = [your job audit table] data = job_details; run;

then call the macro by using:
%job_audit(filename=[the fully qualified path and filename where the sas code is located]);
d507201Database Marketing ConsultantCommented:
I've attached two macros that I use.   They write the information to the program's SAS log itself but could easily be modified to write to a dataset, or both.

The macros will capture the start/end time of an entire program if you pass it the parameter 'program' or you can use them without the parameter to encapsulate a data step/proc or a set of data steps and procs.  Without the parameter they can be used multiple times within a program.

I've thought of modifying them into queries so they can be used within a proc sql with multiple queries to capture the timings for a specific query but never quite got around to it.

Any idea who we talk to get get files with the .sas extension approved for uploading?
Thrawn3000Author Commented:
Hi All
The below code is what, I have so far it creates a temporary table and append it with start time, end time, jobname and job description which are passewd to the macro.

What I wantthe code to do is to create a table in a permanent table in a library , and the subsequent time it is run  to append that log table. The first time I create the dable I also want to set the lenght of the Job_name and Job_description to 200.
any ideas.

/*%Let newVar = SYSDATE;*/
/*%let varStartRunTime=%sysfunc(time());*/

%let varStartRunTime= %sysfunc(datetime(),datetime.10);
%let varEndRunTime= %sysfunc(datetime(),datetime.10);
%let varJobName =  01_01_Build_Segmentation;
%let varJobDescription =TBA;

    %macro logmodelbuild(varJobName,varjobitemdesc,varRunDate,StartRunTime,EndRunTime);

			Data DS5; retain JOB_NAME "&varJobName"  JOB_DESCRIPTION "&varjobitemdesc" RUN_DATE "&varRunDate" RUN_TIME_START "&StartRuntime" RUN_TIME_END "&EndRunTime";

				proc append base=ds8 data=ds5;


			Title "Test Code &logjobnam done";

					proc print data=ds8 noobs;


    %mend logmodelbuild;

Open in new window

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

Aloysius LowConnect With a Mentor Commented:
if you want the table in a permanent library, you'll need to specify a library when doing the proc append:

proc append base=[permanent library name].ds8

if you want the column with a specified length when creating the table, when creating your table DS5, you could specify the length after your data statement:
data ds5;
  length job_name job_description $200.;
  the rest of your code;
Thrawn3000Author Commented:
Thanks, that makes it clear i understand the syntax and logic now.
Thrawn3000Author Commented:
Thanks, that makes it clear i understand the syntax and logic now.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.