| Date: | Tue, 1 Oct 2002 17:27:47 -0400 |
| Reply-To: | Jeff Erickson <Jeff.Erickson@paconsulting.com> |
| Sender: | "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU> |
| From: | Jeff Erickson <Jeff.Erickson@paconsulting.com> |
| Subject: | Re: Saving file with current date in name |
| Content-Type: | text/plain; charset="iso-8859-1" |
|---|
Thanks, Raynald. I checked your syntax and created the following. It does
what I need it to do. I've copied my syntax below. I'm still frustrated that
it takes 16 lines of code to do what seems like should work in three!
Jeff
****************************************************************************
****************************.
* Macro to save current data file with passed name and today's date.
* Create string with date in YYYY-MM-DD format.
STRING #cdate (A11).
STRING #ddate (A11).
STRING #mo (A2).
STRING #tmo (A3).
COMPUTE #cdate=$DATE11.
COMPUTE #tmo=SUBSTR(#cDATE,4,3).
RECODE
#tmo('JAN'='01')('FEB'='02')('MAR'='03')('APR'='04')('MAY'='05')('JUN'='06')
('JUL'='07')
('AUG'='08') ('SEP'='09')('OCT'='10')('NOV'='11')('DEC'='12') INTO #mo.
compute #ddate=concat(substr(#cdate,8,4),'-',#mo,'-',substr(#cdate,1,2)).
* Create macro with today's date hard-coded.
DO IF $casenum=1.
WRITE OUTFILE 'tempdate.sps' /"DEFINE !date()"/#ddate/"!ENDDEFINE.".
END IF.
EXECUTE.
* Run the macro.
INCLUDE 'tempdate.sps'.
****************************************************************************
****************************.
* Create the macro to save the file.
DEFINE !SaveDt (!POS=!CMDEND).
save outfile = !QUOTE(!CONCAT(!UNQUOTE(!1),!EVAL(!date),'.sav')).
!ENDDEFINE.
* Run the macro.
!SaveDt C:\TestNameOfFile.
****************************************************************************
****************************.
----------------------------------------------------------------------
Date: Thu, 26 Sep 2002 21:28:36 -0400
From: Raynald Levesque <rlevesque@videotron.ca>
Subject: Re: Saving file with current date in name
Hi
Did you look at the file "Print current date in chart title.SPS"
in http://pages.infinit.net/rlevesqu/SampleSyntax.htm#ChartsAndTables
If I were you I would use a date of the format YYYY-MM-DD instead of
DD-MMM-YYYY
The advantage of the format I suggest is that when you sort files by
alphabetical order, they are also by date order.
HTH
Raynald Levesque rlevesque@videotron.ca
Visit my SPSS Pages <http://pages.infinit.net/rlevesqu/index.htm>
http://pages.infinit.net/rlevesqu/index.htm
-----Original Message-----
From: Jeff Erickson
Sent: Thursday, September 26, 2002 3:25 PM
To: 'SPSSX-L@listserv.uga.edu'
Subject: Saving file with current date in name
I want to save backup versions of my data files before making significant
changes to them. If I could automatically append the system date (using
$DATE11) to the file name, I could create a history of the changes to the
file. I saw some syntax from Raynald Levesque on January 3rd that I modified
trying to get this to work, but it does not.
The syntax I have tried is as follows:
* --------------------------------------------------------.
DEFINE !SaveDt (VarA = !TOKENS(1) ).
save outfile = !QUOTE(!CONCAT(!UNQUOTE(!VarA),!DATE11,'.sav')).
!ENDDEFINE.
* --------------------------------------------------------.
!SaveDt VarA='C:\Testfile'.
I want this to create a data file named 'C:\Testfile26-SEP-2002.sav' today
and 'C:\Testfile27-SEP-2002.sav' tomorrow. However, it creates a data file
named 'C:\Testfile!DATE11.sav'.
Can anyone point me in the right direction for fixing this?
Thanks,
Jeff
|