[Webinar] Learn how to a build a cloud-first strategyRegister Now


Use log file macro to keep track of jobs

Posted on 2011-10-20
Medium Priority
Last Modified: 2013-11-16
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

Question by:Thrawn3000
  • 3
  • 2
LVL 14

Accepted Solution

Aloysius Low earned 2000 total points
ID: 37006425
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]);

Expert Comment

ID: 37006966
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?

Author Comment

ID: 37015870
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 14

Assisted Solution

by:Aloysius Low
Aloysius Low earned 2000 total points
ID: 37015877
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;

Author Closing Comment

ID: 37023364
Thanks, that makes it clear i understand the syntax and logic now.

Author Closing Comment

ID: 37023365
Thanks, that makes it clear i understand the syntax and logic now.

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month20 days, 9 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question