Return to Archive

SAS Tip of the Month
January 2004

This is not directly a SAS related tip this month but a DOS .BAT file that I find useful when writing programs and wanting to keep a copy of a file with a date/time stamp embedded in the file name, in a backup directory, directly under the directory I am working in. The code for this file is the following:

   if z%1 == z goto usage
   If not exist bkup\Nul MD bkup
   FOR /F "TOKENS=2-4 DELIMS=/ " %%F IN ('DATE /T') DO (SET TODAY=%%F-%%G-%%H)
   FOR /F "TOKENS=1-2 DELIMS=: " %%I IN ('TIME /T') DO (SET NOW=%%I%%J)
   copy %~n1%~x1 bkup\%~n1-%today%-%now%%~x1
   goto end
   echo. Usage is BKUP filename.

The usage for this file, where the code is stored in the file BKUP.BAT, is

BKUP filename

An example of its usage is the file DEMO.SAS where after running the command


the file would appear in the BKUP directory with the name DEMO-01-13-2004-1238.SAS where the "01-13-2004" is the date in local format from the DOS country setting and the "1238" is the time. This code will only work when your operating system is Windows NT, Windows 2000 or Windows XP - it will not work in any other environment. Note that if the directory BKUP is not present then it will be created.

Hope this is useful to at least a few people.

Updated January 13, 2004