Use log file macro to keep track of jobs

Posted on 2011-10-20
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
    LVL 14

    Accepted Solution

    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]);
    LVL 7

    Expert Comment

    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

    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

    LVL 14

    Assisted Solution

    by:Aloysius Low
    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

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

    Author Closing Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now