全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SPSS论坛
1163 0
2014-05-14
We run our database queries with macros. Since we want to run queries every day (for the past day), we would need a dynamic timestamp within the macro. Therefore we tried to combine macro with python by using the command spss.SetMacroValue. But this does not work. What is wrong - or is there any other solution instead of python/macro?
(solutions in SQL slow down the query)

Code:

begin program.
import datetime, string, spss

when = datetime.datetime.today()
first = datetime.date(day=1, month=when.month, year=when.year)
firstThisMonth=first.strftime('%Y-%m-%d %H:%M:%S')
prev_month_end = first - datetime.timedelta(days=1)
prev_month_start = datetime.date(day=1, month= prev_month_end.month, year=
prev_month_end.year)
firstDay=prev_month_start.strftime('%Y-%m-%d %H:%M:%S')

spss.SetMacroValue("!timestamp1", "'" + firstDay+ "'")
spss.SetMacroValue("!timestamp2", "'" +firstThisMonth+ "'")

end program.



DEFINE macdef1 (arg_macdef1 = !TOKENS(1)
                             /  arg_macdef2 = !TOKENS(1)
                              /     arg_macdef3  = !TOKENS(1)).

GET DATA
   /TYPE=ODBC
   /CONNECT= !arg_macdef1
   /SQL=

(...)

  *deliveryDate >= !timestamp1 and deliveryDate < !timestamp2;'*

(...)

   /ASSUMEDSTRWIDTH=255.
CACHE.
EXECUTE.
DATASET NAME !arg_macdef2 WINDOW=FRONT.
SAVE OUTFILE=!arg_macdef3.

!ENDDEFINE.
macdef1 arg_macdef1 = 'DSN=www1;' arg_macdef2 = www1 arg_macdef3 =
'E:\www1.sav'.

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群