Architecting, installing and maintaining your SAS environment

How to - Add DATETIME Suffix to Schedule Program Log's

Accepted Solution Solved
Reply
Super Contributor
Posts: 395
Accepted Solution

How to - Add DATETIME Suffix to Schedule Program Log's

Hello,

 

I'm trying to daily scheduling my SAS projects in Windows operarting system. I want to see the logs in specified path day to day. I need to add date suffix for the log files. I've found a PROC PRINTTO precedure in the internet but when I execute my schedule code by using PROC PRINTTO procedure (in Prog1.sas as below) I get two logs and they seems piece by piece. I mean the .bat file generates one part of log and the PRINTTO procedure generates the other part of log. I need to see whole log day to day with date suffix. I have a similar Schedule code as below and PROC PRINTTO code as below. I also shared my desired logs results as below. Could you help me ,please ? 

PROC PRINTTO 

 

%let T=%SYSFUNC(DATETIME(),DATETIME9.);
%put &T;

proc printto log="<path>\Schedule&T..log";
run;

Schedule Code

FILENAME PROG1 "<path>\Prog1.sas";/* PROC PRINTTO procedure is here */
FILENAME PROG2 "<path>\Prog2.sas";
FILENAME PROG3 "<path>\Prog3.sas";


%INCLUDE PROG1 ;
%INCLUDE PROG2 ;
%INCLUDE PROG3 ;

Desired Log Results

 

Logs.png

 

My .bat scripts

 

"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -SYSIN "<path>\Schedule.sas"

Accepted Solutions
Solution
‎02-21-2016 09:57 AM
Super User
Posts: 7,771

Re: How to - Add DATETIME Suffix to Schedule Program Log's

Use

Schedule%date:~10,4%-%date:~7,2%-%date:~4,2%.log

as the logfile name.

This uses the inbuilt string manipulation functions of the Windows(DOS) shell to extract year, month and day from the system date formatted in your locale's settings.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 7,771

Re: How to - Add DATETIME Suffix to Schedule Program Log's

You need to determine the name for the log file in the batch and hand it over to SAS with the -log commandline option.

proc printto does its job during runtime, and everything up to that point will be written to the generic log file. That's why you get two logs.

A log file specified on the commandline is defined before SAS actually starts working, and will therefore contain everything in one file.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 395

Re: How to - Add DATETIME Suffix to Schedule Program Log's

Posted in reply to KurtBremser

Kurt,

 

Thank you for trying to help me.

 

As far as I understand you want me to write commandline like this ->

 

"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -SYSIN "<path>\Schedule.sas" -LOG" <path>\Schedule.log"

 

But If I write the commandline like that how can I see the whole logs as below. I want to see the logs day to day.

 

Logs.png

 

Thanks.

 

Super User
Posts: 7,771

Re: How to - Add DATETIME Suffix to Schedule Program Log's

In the Windows command processor (cmd.exe), which runs .bat files, you have access to the system environment variables.

One of those is %date%, which holds the current date in your locale's format. You can use that to build the name of the log file.

To manipulate the string, you can use string manipulation capabilities that are inbuilt:

http://www.dostips.com/DtTipsStringManipulation.php

 

I STRONGLY (and I mean STRONGLY) recommend to not use the SAS-typical date format, but something like yyyy-mm-dd!

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 395

Re: How to - Add DATETIME Suffix to Schedule Program Log's

[ Edited ]
Posted in reply to KurtBremser

Oh thanks Kurt,

 

It seems to me it will work but now I have an format problem Smiley Sad If I write "Schedule%Date%.log" into batch file because of "Wed 02/17/2016" format I get error like this ->"Physical file does not exist, <path>\ScheduleWed 02\17\2016.log." I think I need to get rid of the slash(/) characters and blank( ) character to get my desired output. Is there anybody who has experience on Windows command formats ?

 

Thank you.

Solution
‎02-21-2016 09:57 AM
Super User
Posts: 7,771

Re: How to - Add DATETIME Suffix to Schedule Program Log's

Use

Schedule%date:~10,4%-%date:~7,2%-%date:~4,2%.log

as the logfile name.

This uses the inbuilt string manipulation functions of the Windows(DOS) shell to extract year, month and day from the system date formatted in your locale's settings.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 395

Re: How to - Add DATETIME Suffix to Schedule Program Log's

Posted in reply to KurtBremser

Thank you very much Kurt Smiley Happy It is working now. I think I can take the logs day to day.

 

Thanks again.

Super User
Posts: 5,426

Re: How to - Add DATETIME Suffix to Schedule Program Log's

When you say "SAS Projects", do you mean Enterprise Guide projects?

If your deployment have an Intelligence Server component, you could/should register your batch joibs via SAS Management Console. By doing so, you'll get the date/time-stamp of your log files out of the box.

Data never sleeps
Super Contributor
Posts: 395

Re: How to - Add DATETIME Suffix to Schedule Program Log's

LinusH,

 

Yes, I meant Enterprise Guide projects.To make it clear, I will call the SAS programs and they will generate SAS datasets under the specified SAS Library. Actually after Kurt's advises I tried in my local OS and it worked. But we need to do this process in Windows SAS Server machine. I exactly couldn't get your warning during operation. If I do this process in SAS server which road should I follow, Could you explain breifly, please ?

 

Thanks.

Super Contributor
Posts: 395

Re: How to - Add DATETIME Suffix to Schedule Program Log's

i'd like to point out that I won't execute SAS Enterprise Guide project I will call SAS programs as below. Do I still need to consider Management Console definitions before I schedule the SAS program in SAS server.

 

FILENAME PROG1 "<path>\Prog1.sas";
FILENAME PROG2 "<path>\Prog2.sas";
FILENAME PROG3 "<path>\Prog3.sas";


%INCLUDE PROG1 ;
%INCLUDE PROG2 ;
%INCLUDE PROG3 ;

 

Thanks.

Super User
Posts: 5,426

Re: How to - Add DATETIME Suffix to Schedule Program Log's

If you have Management Console it's preferable to use it.
Register your SAS programs in SMC, then put then into a Job flow. No need to use your %include logic. The schedule manager plug in in SMC handles this and deploys the flow directly to WTS.
Data never sleeps
Super Contributor
Posts: 395

Re: How to - Add DATETIME Suffix to Schedule Program Log's

Linush,

 

Thank you for these information.

☑ This topic is solved.

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

Discussion stats
  • 11 replies
  • 845 views
  • 4 likes
  • 3 in conversation