• 大小: 1.96MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-11-04
  • 语言: 其他
  • 标签: spss  统计  编程  

资源简介

SPSS编程,主要介绍spss编程方面的内容

资源截图

代码片段和文件信息

# Find all variables in the current dataset that do not have any value labels.
# This illustrates the use of the spss.CreateXPathDictionary api which produces the entire dictionary
# and the Python xml processing facilities.
# An alternative way of processing the dictionary information is using XPath via the spss.EvaluateXPath api.

# This module is for use with the 3rd Edition of SPSS Programming and Data Management.
# To make use of this module copy it to your Python “site-packages“ directory which is typically
# C:\Python24\Lib\site-packages. This module makes use of the spss module which is available once you‘ve
# installed the SPSS-Python Integration Plug-In.

#pubsmarker:import_start
from xml.sax.handler import ContentHandler
import xml.sax
import random codecs locale
import spss
#pubsmarker:import_end

# This class extracts the list of variables from the variable dictionary and determines which ones have 
# value labels by using the xml.sax module.
# The StartElement method of the content handler sees every element in the variable dictionary.
# It selects only variable name and value label information and updates the sets as they appear.
# These are later retrieved from the handler object.

# It may be helpful in working through this example to look at actual dictionary xml.  You can
# produce a file of this using something like
#   spss.GetxmlUtf16(tag filespec)
# where tag identifies the output of spss.CreateXPathDictionary in the xml workspace.

__author__ =  ‘spss‘
__version__=  ‘1.0.0‘

# History
#  22-Mar-2006  Initial version

#pubsmarker:labelhandler_start
class valueLabelHandler(ContentHandler):
    “““Create two sets: one listing all variable names and
    the other listing variables with value labels“““
    def __init__(self):
        self.varset = set()
        self.vallabelset = set()
    def startElement(self name attr):
        if name == u“variable“:
            self.varset.add(attr.getValue(u“name“))
        elif name == u“valueLabelVariable“:
            self.vallabelset.add(attr.getValue(u“name“))
#pubsmarker:labelhandler_end

# Use the class above to find variables without value labels

#pubsmarker:varsnolabels_start
def FindVarsWithoutValueLabels():
    handler = valueLabelHandler()
    tag = “D“+ str(random.uniform(01))
    spss.CreateXPathDictionary(tag)

    # Retrieve and parse the variable dictionary
    xml.sax.parseString(spss.GetxmlUtf16(tag)handler)
    spss.DeleteXPathHandle(tag)

    # Print a list of variables in varset that aren‘t in vallabelset
    # Convert from Unicode to the current character set
    nolabelset = handler.varset.difference(handler.vallabelset)
    encoding = locale.getlocale()[1]
    if nolabelset:
        print “The following variables have no value labels:“
        print “\n“.join([codecs.encode(vencoding) for v in nolabelset])
    else:
        print “All variables in this dataset have at least one value label.“
#pubsmarker:varsnolabels_end    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        216  2004-05-07 08:23  examples\commands\access1.sps

     文件        308  2004-05-07 08:24  examples\commands\access2.sps

     文件        311  2004-05-07 08:24  examples\commands\access_multtables1.sps

     文件        190  2004-05-07 08:24  examples\commands\add_files1.sps

     文件        599  2006-02-15 11:17  examples\commands\add_files2.sps

     文件        410  2004-05-11 12:30  examples\commands\aggregate1.sps

     文件        343  2004-05-11 12:30  examples\commands\aggregate2.sps

     文件        710  2006-01-12 14:48  examples\commands\append_to_table.sps

     文件        693  2004-05-07 08:26  examples\commands\apply_properties.sps

     文件        215  2004-05-07 08:26  examples\commands\asynchro_example1.SPS

     文件        176  2004-05-07 08:26  examples\commands\asynchro_example1a.sps

     文件        293  2004-05-07 08:26  examples\commands\casestovars.sps

     文件       2548  2004-05-07 08:26  examples\commands\Challenge_Find_Variables_With_Missing_Labels.SPS

     文件        662  2004-05-07 08:27  examples\commands\check.sps

     文件        286  2006-01-16 17:26  examples\commands\concat_string.sps

     文件        623  2004-05-07 08:27  examples\commands\conditional_include.sps

     文件        619  2004-08-05 14:18  examples\commands\conditional_insert.sps

     文件        297  2006-01-05 12:07  examples\commands\dataset_subsets.sps

     文件        505  2006-01-11 16:59  examples\commands\data_validation.sps

     文件        337  2004-05-11 12:29  examples\commands\datediff.sps

     文件        186  2004-05-11 12:30  examples\commands\datesum.sps

     文件        430  2004-05-07 08:27  examples\commands\date_functions.sps

     文件        474  2006-03-27 12:06  examples\commands\date_functions2.sps

     文件        416  2004-05-07 08:28  examples\commands\date_functions3.sps

     文件        474  2004-08-05 14:19  examples\commands\decimal_indicator.sps

     文件        363  2004-08-05 14:19  examples\commands\define_globals.sps

     文件       1401  2004-05-07 08:29  examples\commands\define_variables.sps

     文件        247  2004-05-07 08:29  examples\commands\delimited_csv.sps

     文件        220  2006-01-04 14:24  examples\commands\delimited_formats.sps

     文件        142  2004-05-07 08:29  examples\commands\delimited_list.sps

............此处省略268个文件信息

评论

共有 条评论