Dynamically use current date in OUTPUT EXPORT filename

Viewed 112

Stripped down example code using a static file name:

OUTPUT EXPORT /CONTENTS EXPORT=ALL /PDF DOCUMENTFILE='example.pdf'

My question is how to generate a datestamped file. I have tried using $DATE, '$DATE' and running it through a macro but can't seem to find the syntax.

1 Answers

Hey this is a really nice Idea for saving backups in a running syntax production - I will use this myself from now on :) . So the following syntax works for me:

compute tdy= $time.
formats tdy (date11).
temporary.
select if $casenum=1.
write out="somepath\datemacro.sps" /"define !dated__filename ()  !quote(!concat('YOUR FILE NAME',' ','", tdy, "','.pdf'))  !enddefine.".
exe.
Insert file ="somepath\datemacro.sps".
delete vars tdy.

The file name you used in the code above is now stored in a macro with the date added, and you can use it here:

OUTPUT EXPORT /CONTENTS EXPORT=ALL /PDF DOCUMENTFILE= !dated__filename .

Note that you can change "YOUR FILE NAME" into anything you like, including adding a path. And you can also change ".pdf" so save other kinds of files. EDIT: Also of course change "somepath" to a valid path on your machine.

Related