Hi Ron,
Now you'll get what you want. The following is an (initial) elaboration of
your and my ideas on how to enable a DateTimeStamp in log and print output
file names.
Short algorithm description
===========================
Log and print output files may be changed from within a SAS session using
PROC PRINTTO, but as Ron Fehd correctly pointed out, any subsequent use of
PROC PRINTTO, followed by a call to PROC PRINTTO to reset the output
streams to default (without LOG= and PRINT= specifications, or with their
resp. LOG and PRINT specifications), would not reset the destinations to
the DateTimeStamped file names. That only occurs if the specifications are
done at the time of SAS starting up, i.e. in the command line specification
of the -log and -print options. And that is what will be done.
Before running SAS batch with the specified program name as its -sysin
argument a program is run, which interpretes the [drive:][path\]filename
[.ext] specification of the program to run and generates DateTimeStamped
file specifications for both the log and print files. These file
specifications are specified while calling SAS with the program to run. The
initial program generating the DateTime Stamped file specifications could
be any program, written in any language, but here it is a SAS program,
which runs an initial instance of SAS batch.
The whole sequence of programs to run is called from a DOS batch file (i.e.
SASstamp.bat) (which may be found via the search PATH), that needs the
program [path and] name to run as its argument. This DOS script start SAS
with the just mentioned DateTimeStamping program (here [drive:][path\]
SASstamp.sas) as the -sysin argument and the program to run as the -sysparm
arugument. The SASstamp.sas program generates the DateTimeStamped file
names and a DOS command to call another batch file SAS8BAT.bat with a
similar syntax and explicit specifications for the log and print files. The
SASstamp.bat file itself suppresses its log and print output while
specifying 'nul' as their destinations.
Installation and adaptation
===========================
1. Put both DOS batch files SASstamp.bat and SAS8BAT.bat somewhere in your
search path, to be able to start them just by calling their name from
anywhere.
2. Put the SASstamp.sas program anywhere on your disk and adapt the DOS
batch file SASstamp.bat to contain the right path to SASstamp.sas .
Additional adaptations of DOS batch code may be necessary, dependent on SAS
and file locations and names. Possibly remove (comment out with REM) the
file existence check in the batch files.
Short directions for use
========================
Syntax: SASstamp <<program-name_to_run>> [other options]
Disclaimer
==========
The limited, but correctly working DOS batch language does not always seem
to be able to cope with long Windows file names, especially if containing
spaces and other exotic characters! The DOS batch files only have 9
variable parameters which may contain file name parts if (one or more)
embedded spaces are concerned, leaving too less registers for the
remaining, but very necessary arguments! Sticking to the 8.3 convention is
safest and works always correctly, deviations might work, but are not
guaranteed to work (correctly). This is where since the introduction of
Windows a rather limited, but consistent command language and its further
development has almost completely been neglected by MS, one of the lacks or
partial incompatibilities of Windows with DOS.
I have experimented with Windows95, Windows98, Windows2K, DOS command lines
and DOS batch files. A DOS command line has a limit of 127 characters
(after substituting environment variables). This limitation does not always
show from DOS batch files under Windows, but I'm not sure whether long
batch file lines always work correctly.
This strategy might be adapted for Unix (and possibly other platforms as
well). Unix (and Linux) scripts do not suffer from limitations as DOS batch
files do.
Well, this development is a preliminary one and may possibly be improved
and extended.
SASstamp.bat
============
@echo off
echo --- SASstamp.bat --- (C) Jim Groeneveld, 25 October 2004.
echo.
rem Date and time stamping log and print output and starts SAS in batch
mode.
if "%1"=="" goto Help
if not exist %1 goto NotExist (not guaranteed to always work correctly)
rem Switch to the drive the SAS_application is in:
%1\
rem Switch to the directory the SAS_application is in (to make it current):
cd %1\..
rem ...for use with options {ALT}LOG and {ALT}PRINT...
rem ...but these are redundant to specify the default drive/dir...
rem Otherwise the results are written to the drive/dir of this BATch file.
echo Starting SAS in batch mode. This window will disappear automatically.
start c:\Progra~1\SASIns~1\SAS\V8\sas -config c:\Progra~1\SASIns~1\SAS\V8
\sasv8.cfg -sysin y:\tmp\SASstamp.sas -sysparm %1 -log 'nul' -print 'nul' -
nosplash %2 %3 %4 %5 %6 %7 %8 %9
rem Adapt location of SASstamp.sas as desired.
goto End
:NotExist
echo File %1 does not exist!
echo.
:Help
echo Syntax from the DOS prompt: %0 «SAS_application_file»
echo ... or drag (in Windows) the SAS_application_icon to this
echo .BATch_file_icon (or its shortcut on the desktop).
pause
rem goto End
:End
----------
SASstamp.sas
============
OPTIONS NOXWAIT;
DATA _NULL_;
Sysparm = GETOPTION('Sysparm'); * may lack (partial) path specification;
FileSpec = SCAN ( Sysparm, -1, ':\');
IF (LENGTH ( Sysparm ) - LENGTH ( FileSpec ) GT 0) THEN
FilePath = SUBSTR ( Sysparm, 1, LENGTH ( Sysparm ) - LENGTH (
FileSpec ) );
ELSE FilePath = ''; * (because idiot SUBSTR does not allow 0 as 3rd arg);
LastChar = LENGTH ( FileSpec ) - INDEX ( REVERSE ( TRIM (
FileSpec ) ), '.' );
FileName = SUBSTR ( FileSpec, 1, LastChar);
CurDate = COMPRESS ( PUT ( DATE(), YYMMDD10.), '-' );
CurTime = COMPRESS ( PUT ( TIME(), TIME. ), ':' );
IF (FilePath NE '') THEN
FullSpec = TRIM(FilePath) || TRIM(FileName) || '.'
|| TRIM(CurDate) || '.' || TRIM(CurTime) || '.' ;
ELSE /* (because idiot empty string represents single, unwanted space) */
FullSpec = TRIM(FileName) || '.'
|| TRIM(CurDate) || '.' || TRIM(CurTime) || '.' ;
FullCmd = 'cmd /c Sas8bat "' || TRIM(Sysparm) || '" -log "' ||
TRIM(FullSpec) || 'log" -print "' ||
TRIM(FullSpec) || 'lst"' ;
CALL SYSTEM (TRIM(FullCmd));
RUN;
* SAS batch session terminates here; * another one is started via CALL
SYSTEM;
----------
SAS8BAT.bat
===========
@echo off
echo --- SASbatch.bat --- (C) Jim Groeneveld, 30 Oct 2001.
echo.
rem starts SAS in batch mode.
echo Feedback: %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
if "%1"=="" goto Help
if not exist %1 goto NotExist (not guaranteed to always work correctly)
rem Switch to the drive the SAS_application is in:
%1\
rem Switch to the directory the SAS_application is in (to make it current):
cd %1\..
rem ...for use with options {ALT}LOG and {ALT}PRINT...
rem ...but these are redundant to specify the default drive/dir...
rem Otherwise the results are written to the drive/dir of this BATch file.
echo Starting SAS in batch mode. This window will disappear automatically.
start c:\Progra~1\SASIns~1\SAS\V8\sas -config c:\Progra~1\SASIns~1\SAS\V8
\sasv8.cfg -sysin %1 -nosplash %2 %3 %4 %5 %6 %7 %8 %9
goto End
:NotExist
echo File %1 does not exist!
echo.
:Help
echo Syntax from the DOS prompt: %0 «SAS_application_file»
echo ... or drag (in Windows) the SAS_application_icon to this
echo .BATch_file_icon (or its shortcut on the desktop).
rem Marking and clicking File in My Computer or Explorer and subsequently
rem clicking Batch Submit also yields the results in the drive/directory
rem of the application to run. Dit only applies to .SAS and .SS2 files.
rem Dragging the SAS_application_icon of some application to run to (the
rem shortcut of) SAS itself undesiredly results in the output on the
desktop.
pause
rem goto End
:End
----------
Regards - Jim.
--
Y. (Jim) Groeneveld, MSc., Biostatistician, Science Team
Vitatron B.V., Meander 1051, 6825 MJ Arnhem
P.O.Box 5227, 6802 EE Arnhem, the Netherlands
Tel: +31/0 26 376 7365, Fax: +31/0 26 376 7305
Jim.Groeneveld_AT_Vitatron.com (replace _AT_ by AT sign)
http://www.vitatron.com, http://home.hccnet.nl/jim.groeneveld
My computer multi-boots OS's, each of them adapting the DST twice a year.
[common disclaimer]
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-***@LISTSERV.UGA.EDU]On Behalf Of
Fehd, Ronald J.
Sent: Friday, October 22, 2004 16:37
To: SAS-***@LISTSERV.UGA.EDU
Subject: Re: What do you change to have a unique/numbered LOG/LST name?
good solution, Jim
however, this will fail
if the job contains another PrintTo
- - - JobA - - -
*autoexec happens here;
Proc PrintTo log = "<&SysIn.&datestamp..log>";
.... some processing including use of:;
Proc PrintTo ...;
*this will disable the above date-stamp allocation;
Proc PrintTo;*end of log = "<&SysIn.&datestamp..log>";
- - - JobA end - - -
in my testing I saw that the only guaranteed way
to have a date-stamped log and list
was to allocate the filenames for altlog and altprint
in a configuration file
one method I developed in testing the date-stamped file-specs was:
- - - JobA.bat - - -
set JobName=JobA
sas -sysin DateStampAltLog -sysparm %JobName%
sas -config Project.cfg -sysin %JobName%
- - - JobA.bat end - - -
where altlog.cfg looks something like:
- - - altlog.cfg - - -
-altlog !ProjRoot\altlog\JobA20042960938.log
-altprint !ProjRoot\altlog\JobA20042960938.txt
- - - altlog.cfg end - - -
note the above date-stamp is hand-typed,
not the output of DateStampAltLog.sas
and
- - - Project.cfg - - -
-config u:\dls\SAS\sitev91.cfg /*calls SAShome/SASv9.cfg*/
-config altlog.cfg
-SET ProjRoot u:\DLS\ODTB\NTM\p2004_06
-SASinitialFolder !ProjRoot\pgm
- - - Project.cfg - - -
note that this writes the alt*.* to a separate folder
read the .sig
this replicates what I am doing in theory
but not exactly in practice
Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
--> cheerful provider of UNTESTED SAS code from the Clue?Gee!Wrx <--