如何从SPSS Custom Tables中检索一些输出值?

时间:2015-04-24 22:59:25

标签: xml spss

我一直在尝试从SPSS Custom Tables中检索一些特定的输出值并将它们导出到Excel。 问题是我的Ctables语法生成了2个不同的表,我想从这两个表中检索一些特定的输出值,然后导出到Excel。 Link to screenshot of SPSS custom tables。我已经突出显示了我要检索的红色值。我试图以XML格式检索这些值,但我收到一条错误消息。这是代码。

      *1. Retrieve some output values and insert them into text.
 begin program.
import spssaux
gar="CTABLES
    /VLABELS VARIABLES=Institution RES_PAY Status DISPLAY=LABEL
    /TABLE  Status [C] > RES_PAY [C] BY Institution [C][COUNT F40.0, COLPCT.COUNT PCT40.1]
   /CATEGORIES VARIABLES=Institution ORDER=A KEY=VALUE EMPTY=INCLUDE  TOTAL=YES POSITION=AFTER
   /CATEGORIES VARIABLES=RES_PAY EMPTY=INCLUDE
   /CATEGORIES VARIABLES=Status ORDER=A KEY=VALUE EMPTY=INCLUDE
   /SIGTEST TYPE=CHISQUARE ALPHA=0.05 INCLUDEMRSETS=YES  CATEGORIES=ALLVISIBLE."


   cmd = spssaux.CreateXMLOutput(gar, visible=True)
   result=spssaux.GetValuesFromXMLWorkspace(cmd, 'CTABLES', cellAttrib ='text',colCategory='Cat1', rowCategory='Research with pay',rowSubCategory='Yes')
   result1=spssaux.GetValuesFromXMLWorkspace(cmd, 'CTABLES', tableSubtype='CHISQUARE', cellAttrib = 'text',colCategory='Status', rowCategory='Research with pay',rowSubCategory='Sig.')
   OUTPUT NEW
   print result[1]
   print result1[1]

   end program.

  *2. Export output to Excel.

  OUTPUT EXPORT
  /CONTENTS EXPORT= ALL LAYERS=PRINTSETTING MODELVIEWS=PRINTSETTING
 /XLSX DOCUMENTFILE='U:/report1.xlsx' 
 OPERATION=CREATEFILE 
 LOCATION=STARTCELL('C4') NOTESCAPTIONS=YES.

这是我收到的错误消息

 File "<string>", line 4
    gar="CTABLES
     SyntaxError: EOL while scanning string literal      ^

有人可以帮我解释一下代码吗?

1 个答案:

答案 0 :(得分:1)

Python代码中存在语法错误。以gar =开头的行引入了一个多行文字,所以你需要将它括在三引号中,

GAR =&#34;&#34;&#34; CTABLES
    / VLABELS VARIABLES =机构RES_PAY状态DISPLAY = LABEL
    / TABLE状态[C]&gt; RES_PAY [C] BY机构[C] [COUNT F40.0,COLPCT.COUNT PCT40.1]
   / CATEGORIES VARIABLES =机构订单= A KEY = VALUE EMPTY = INCLUDE TOTAL = YES POSITION = AFTER
   / CATEGORIES VARIABLES = RES_PAY EMPTY = INCLUDE
   / CATEGORIES VARIABLES =状态ORDER = A KEY = VALUE EMPTY = INCLUDE
   / SIGTEST TYPE = CHISQUARE ALPHA = 0.05 INCLUDEMRSETS = YES CATEGORIES = ALLVISIBLE。&#34;&#34;&#34;

但是,一旦获得这些值,您只需将它们打印到Viewer并将所有内容导出到Viewer,这可能不是您想要的,因为这些值已经存在于将要导出的表中。这似乎是一种非常迂回的方式来做这一切。也许如果你描述整个过程,可以找到一个更简单的解决方案。