我的数据集有三个日期字段(adate10):Period,Version和Created。对于所有情况,每个字段的值都相同。让我们说值是:
Period = 10/01/17
Version = 11/15/17
Created = 11/25/17
我想将所有三个日期传递给SAVE OUTFILE='C:\Users\Inventory ? ? ?...
命令,因此文件名为:
C:\MyData\Inventory p20171001 v20171115 c20171125.sav
如何将这三个日期字段的值传递给save命令?我认为Python是可行的方法,但无法弄清楚语法。我在下面的链接中看到了几个解决方案,但它们都只涉及一个日期字段;我有三个。 (即使我尝试了一个约会,我也无法让它们中的任何一个工作)。
答案 0 :(得分:2)
这里有一点Python:
BEGIN PROGRAM.
import spss, spssdata
# names of date variables (case sensitive)
varlist = ['period', 'version', 'created']
# fetch dates from dataset and format them to YYYYMMDD
data = spssdata.Spssdata(indexes=(varlist), cvtDates=(varlist))
dates = [date.strftime("%Y%m%d") for date in data.fetchone()]
data.close()
# Create 'save command' command and submit it to spss
spss.Submit(r"""
SAVE OUTFILE = 'C:\MyData\Inventory p{0} v{1} c{2}.sav'.
""".format(*dates))
END PROGRAM.
答案 1 :(得分:0)
You can get the results you need with syntax only:
TEMPORARY.
select if $casenum=1.
format Period Version Created (f11).
write out="C:\MyData\save with dates in name.sps"
/"save out='C:\MyData\Inventory p", Period, " v", Version, " c", Created, ".sav' ".
exe.
insert file="C:\MyData\save with dates in name.sps".