BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
turcay
Lapis Lazuli | Level 10

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"
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

11 REPLIES 11
Kurt_Bremser
Super User

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.

turcay
Lapis Lazuli | Level 10

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.

 

Kurt_Bremser
Super User

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!

turcay
Lapis Lazuli | Level 10

Oh thanks Kurt,

 

It seems to me it will work but now I have an format problem 😞 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.

Kurt_Bremser
Super User

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.

turcay
Lapis Lazuli | Level 10

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

 

Thanks again.

LinusH
Tourmaline | Level 20

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
turcay
Lapis Lazuli | Level 10

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.

turcay
Lapis Lazuli | Level 10

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.

LinusH
Tourmaline | Level 20
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
turcay
Lapis Lazuli | Level 10

Linush,

 

Thank you for these information.

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

Get Started with SAS Information Catalog in SAS Viya

SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.

Find more tutorials on the SAS Users YouTube channel.

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