I am trying to simplify a syntax, which in future will be used by others.<br>
In the syntax I use OUTPUT EXPORT to create an Excel file and after this to add new sheets with data. I do this with the following syntax:
begin program.
import time, spss
spss.SetMacroValue("!timestamp", "'" + time.strftime("%Y-%m-%d") + "'")
end program.
OUTPUT EXPORT
/CONTENTS EXPORT=VISIBLE
/XLSX DOCUMENTFILE ='U:/Data/ get sundhed for b rn/K benhavnerbarometer/KB-Sund_2011-2013 ' + !timestamp + '.xlsx'
OPERATION=CREATEFILE
SHEET='Livskvalitet'
LOCATION=STARTCELL('A1').
OUTPUT EXPORT
/CONTENTS EXPORT=VISIBLE
/XLSX DOCUMENTFILE ='U:/Data/ get sundhed for b rn/K benhavnerbarometer/KB-Sund_2011-2013 ' + !timestamp + '.xlsx'
OPERATION=CREATESHEET
SHEET='Skoletilfredshed'
LOCATION=STARTCELL('A1').
This all works very nicely, but in order to make it simpler for other users to save output to a different location I want to specify the path and filename once in a variable in the beginning of the syntax and then use this variable in the rest of the syntax.
I can make this work by specifying the filename in the python code, except that it does not work when path or filename contains the Danish letter , and presumably not with and either. I cannot make it work by specifying the path and filename in a SPSS string variable in the syntax. How can this be done?
Regards
Lars
Answer by Ellebjerg (0) | Feb 12, 2014 at 09:07 AM
I am not familiar with Python, just found this solution through google, so my python solution was simply to use the same code as for the timestamp, only specifying the entire path and filename. This worked nicely without the Danish letter but not with it. A possible work around could be to specify that the three Danish letters cannot be part of the path or filename, but as is in the project name, this would be awkward.
I am working in SPSS v. 22. I can see that I am running Unicode. This could explain the problem. I will try shifting to 'OS writing system'.
Answer by JonPeck (4671) | Feb 12, 2014 at 01:43 PM
For the file name, you don't need Python code. You can just do something like this and the o-slash and other extended characters will work.
define !filespec() 'c:/temp/ abc.pdf' !enddefine.
OUTPUT EXPORT
/CONTENTS EXPORT=ALL LAYERS=ALL MODELVIEWS=ALL
/PDF DOCUMENTFILE=!filespec
...
Output Export Problem 3 Answers
How to use custom dialog variable list in CTABLES /TABLE subcommand 2 Answers
bugs in SPSS22? 9 Answers
Warnning message appeard occasionally 2 Answers
Clear output in the output windows 2 Answers