Topic
  • 13 replies
  • Latest Post - ‏2014-07-23T17:08:01Z by David VW
David VW
David VW
19 Posts

Pinned topic Problem & SETSMACRO issue

‏2014-07-02T16:23:30Z |

Problem: I want to dynamically create variable sets to be used in downstream procedures like AGGREGATE, RECODE, or any commands that accept comma-separated (or space-separated) variable lists. I plan on using variable attributes captured from other datasets whose contents refer to variables within the active dataset. For example, my meta-dataset might contain variables (fields) called 'variable' & 'attribute'. 'Variable' has rows corresponding to variables in the active dataset, and 'attributes' contains selection criteria for building variable lists dynamically. Ultimately, I want to create a procedure that will process any dataset conforming to some standard criteria but having different variable names and variable lists but to produce a common analytic output using common commands. Hope that makes sense.

Issue: I thought SETSMACRO looked promising, and it does produce a space-separated variable list to an output file that I define. First issue is that this does not allow me to optionally produce a comma-separated list, which is required for some commands (Spaces work for many but not all: MEAN(var1 var2) does not work). My other issues begin when I attempt to input my own of either  setname or macroname args. I do have variable sets defined using the GUI (Utilities > Define Variable Sets):

BEGIN PROGRAM.
import spss, SETSMACRO
SETSMACRO.SetMacroFromVariableSets(setnames=all, macroname=None, fail=True, outfile='D:\\temp.txt')
END PROGRAM.

Custom setname error:

Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "C:\Program Files\IBM\SPSS\Statistics\22\\extensions\SETSMACRO.py", line 35, in SetMacroFromVariableSets
    setnames = setnames.split()
AttributeError: 'builtin_function_or_method' object has no attribute 'split'

Custom macroname error:

Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "C:\Program Files\IBM\SPSS\Statistics\22\\extensions\SETSMACRO.py", line 60, in SetMacroFromVariableSets
    spss.SetMacroValue(macroname, " ".join(variables))
  File "C:\PROGRA~1\IBM\SPSS\STATIS~1\22\Python\Lib\site-packages\spss\spss.py", line 1587, in SetMacroValue
    Submit(("define "+MName+"()",__toString(MValue),"!enddefine."))
TypeError: cannot concatenate 'str' and 'builtin_function_or_method' objects

Updated on 2014-08-14T15:43:26Z at 2014-08-14T15:43:26Z by David VW
  • JonPeck
    JonPeck
    343 Posts
    ACCEPTED ANSWER

    Re: Problem & SETSMACRO issue

    ‏2014-07-22T19:44:23Z  
    • David VW
    • ‏2014-07-22T14:32:33Z

    That will be great, Jon. I'll look forward to it.

    Try the attached file.  Note that the invoking signature has changed in order to accommodate the attributes variables, which are given as a list to the last argument.  The number and names for the attributes can be whatever you want.

    The test file constructs a metadata dataset, a target dataset, and runs the transfer code.  I noticed that the dataset names are hardwired in your code even though the target dataset name is a parameter.

     

    Attachments

  • JonPeck
    JonPeck
    343 Posts

    Re: Problem & SETSMACRO issue

    ‏2014-07-02T19:05:03Z  

    David,

    The SPSSINC SELECT VARIABLES comes closer to what you want.  It generates a macro definition based on various variable properties, and you can specify what separator you want (default is blank but any character(s) can be used.

    SELECT VARIABLES is designed to work with dictionary properties, not data.  Can you get the attributes column set up instead as custom attributes?  Then you would be all set.  If not, then a small Python program that read the values of the two columns could either create custom attributes or could build the required macro definition directly.

    As for this line,

    SETSMACRO.SetMacroFromVariableSets(setnames=all, macroname=None, fail=True, outfile='D:\\temp.txt')

    If you don't specify a macro name, as here, no macro is created.  As for all, It probably needs to be ALL, but I am not sure that the built-in set names are available.  I can look at this next week when I get back to the office.

    -Jon

     

  • David VW
    David VW
    19 Posts

    Re: Problem & SETSMACRO issue

    ‏2014-07-02T19:43:08Z  
    • JonPeck
    • ‏2014-07-02T19:05:03Z

    David,

    The SPSSINC SELECT VARIABLES comes closer to what you want.  It generates a macro definition based on various variable properties, and you can specify what separator you want (default is blank but any character(s) can be used.

    SELECT VARIABLES is designed to work with dictionary properties, not data.  Can you get the attributes column set up instead as custom attributes?  Then you would be all set.  If not, then a small Python program that read the values of the two columns could either create custom attributes or could build the required macro definition directly.

    As for this line,

    SETSMACRO.SetMacroFromVariableSets(setnames=all, macroname=None, fail=True, outfile='D:\\temp.txt')

    If you don't specify a macro name, as here, no macro is created.  As for all, It probably needs to be ALL, but I am not sure that the built-in set names are available.  I can look at this next week when I get back to the office.

    -Jon

     

    Hi Jon,

    RE SETSMACRO errors: I had to define the var set, 'all', using the GUI (would be nice to define according to externally-derived attributes syntactically, or it obviates the usefulness of dynamically defining var sets). Not specifying a 'setnames' or 'macroname' and leaving as 'None' produces a horizontal var list (with char-limit breaks) output to the defined file, including all vars that I designate in my defined var set. However, if I specify 'setnames=all' I get the error indicated previously. Same goes for setting 'macroname' likewise or as all caps (second traceback applies). Setting both to 'all' (my set name) results in the first error again.

    RE SPSSINC SELECT VARIABLES: This is indeed the functionality I need and was hoping there was a better alternative than hacking SETSMACRO. Now my only problem is in assigning the appropriate custom attributes. I use a module called 'copyMetadata' to assign data from one dataset to the dictionary of another. I assume some variation of this would apply, since I have the attributes of interest expressed as columns (variables) assigned to my variables in the working dataset like so:

    Atrtributes dataset:

    VARIABLE  ATTRIBUTE1     ATTRIBUTE2     ATTRIBUTE3
    var1             2                         1                           string1
    var2            2                          1                           string2
    var3            4                          0                           string1
    var4            4                          1                           string2
    var5            3                          0                           string3

    Working dataset

    var1   var2   var3   var4   var5

    I assume that it is possible to dynamically generate the needed syntax:

    SPSSINC SELECT VARIABLES MACRONAME="MyMacro" VARIABLES=var1   var2   var4 .

    ... where ATTRIBUTE2 = 1

    copyMetadata module:

    # Collect metadata from one dataset and apply to matching variables in another.
    # Only intended for numeric variables
    # Both datasets should have a dataset name

    import spss, spssaux, spssdata

    class Metadata(object):
        """structures to hold metadata"""
        
        def __init__(self):
            self.data = {}
            
        def varlabel(self, name, label):
            name = name.lower().rstrip()
            if not name in self.data:
                self.data[name] = {}
                self.data[name]['vallabels'] = {}
            label = label.rstrip()
            if not label == "":
                self.data[name]['label'] = label
            
        def vallabels(self, name, value, label):
            name = name.lower().rstrip()
            if not value is None:
                self.data[name]['vallabels'][value] = label.rstrip()
            
        def copy(self, name):
            name = name.lower()
            if not name in self.data:
                return
            varlabel = self.data[name].get('label', "")
            if not varlabel == "":
                spss.Submit("""variable label %(name)s "%(varlabel)s".""" % locals())
            vallabels = [str(val) + ' "%s"' % label for val, label in self.data[name]['vallabels'].items()]
            if len(vallabels) > 0:
                vlstr = " ".join(vallabels)
                spss.Submit(""" value labels %(name)s  %(vlstr)s """ % locals())

    def copyMetadata(target, name, varlabel, value, vallabel):
        """Read variables containing metadata from active dataset and apply to another dataset.
        
        Target is the dataset name whose variable metadata will be updated.
        In the source (active) dataset,
         name is the variable containing variable names
         varlabel contains variable labels
         value and vallabel contain value/value label pairs.  (Last entry for a variable wins)
        
        Metadata for variables not in the target dataset are ignored."""
        

        sourcevars = [name, varlabel, value, vallabel]
        mdata = Metadata()
        
        curs = spssdata.Spssdata(sourcevars)
        for case in curs:
            mdata.varlabel(case[0], case[1])
            mdata.vallabels(case[0], case[2], case[3])
        curs.CClose()
        
        spss.Submit("""
        DATASET ACTIVATE TARGET.
        DATASET CLOSE METADATA.
        """)
        vardict = spssaux.VariableDict()
        for v in vardict.variables:
            mdata.copy(v)

    (incidentally, the code (<>) mechanism of your ckEditor does not behave for me ... using Pale Moon variant of Firefox)

    Updated on 2014-07-02T19:58:44Z at 2014-07-02T19:58:44Z by David VW
  • David VW
    David VW
    19 Posts

    Re: Problem & SETSMACRO issue

    ‏2014-07-03T17:36:25Z  
    • David VW
    • ‏2014-07-02T19:43:08Z

    Hi Jon,

    RE SETSMACRO errors: I had to define the var set, 'all', using the GUI (would be nice to define according to externally-derived attributes syntactically, or it obviates the usefulness of dynamically defining var sets). Not specifying a 'setnames' or 'macroname' and leaving as 'None' produces a horizontal var list (with char-limit breaks) output to the defined file, including all vars that I designate in my defined var set. However, if I specify 'setnames=all' I get the error indicated previously. Same goes for setting 'macroname' likewise or as all caps (second traceback applies). Setting both to 'all' (my set name) results in the first error again.

    RE SPSSINC SELECT VARIABLES: This is indeed the functionality I need and was hoping there was a better alternative than hacking SETSMACRO. Now my only problem is in assigning the appropriate custom attributes. I use a module called 'copyMetadata' to assign data from one dataset to the dictionary of another. I assume some variation of this would apply, since I have the attributes of interest expressed as columns (variables) assigned to my variables in the working dataset like so:

    Atrtributes dataset:

    VARIABLE  ATTRIBUTE1     ATTRIBUTE2     ATTRIBUTE3
    var1             2                         1                           string1
    var2            2                          1                           string2
    var3            4                          0                           string1
    var4            4                          1                           string2
    var5            3                          0                           string3

    Working dataset

    var1   var2   var3   var4   var5

    I assume that it is possible to dynamically generate the needed syntax:

    SPSSINC SELECT VARIABLES MACRONAME="MyMacro" VARIABLES=var1   var2   var4 .

    ... where ATTRIBUTE2 = 1

    copyMetadata module:

    # Collect metadata from one dataset and apply to matching variables in another.
    # Only intended for numeric variables
    # Both datasets should have a dataset name

    import spss, spssaux, spssdata

    class Metadata(object):
        """structures to hold metadata"""
        
        def __init__(self):
            self.data = {}
            
        def varlabel(self, name, label):
            name = name.lower().rstrip()
            if not name in self.data:
                self.data[name] = {}
                self.data[name]['vallabels'] = {}
            label = label.rstrip()
            if not label == "":
                self.data[name]['label'] = label
            
        def vallabels(self, name, value, label):
            name = name.lower().rstrip()
            if not value is None:
                self.data[name]['vallabels'][value] = label.rstrip()
            
        def copy(self, name):
            name = name.lower()
            if not name in self.data:
                return
            varlabel = self.data[name].get('label', "")
            if not varlabel == "":
                spss.Submit("""variable label %(name)s "%(varlabel)s".""" % locals())
            vallabels = [str(val) + ' "%s"' % label for val, label in self.data[name]['vallabels'].items()]
            if len(vallabels) > 0:
                vlstr = " ".join(vallabels)
                spss.Submit(""" value labels %(name)s  %(vlstr)s """ % locals())

    def copyMetadata(target, name, varlabel, value, vallabel):
        """Read variables containing metadata from active dataset and apply to another dataset.
        
        Target is the dataset name whose variable metadata will be updated.
        In the source (active) dataset,
         name is the variable containing variable names
         varlabel contains variable labels
         value and vallabel contain value/value label pairs.  (Last entry for a variable wins)
        
        Metadata for variables not in the target dataset are ignored."""
        

        sourcevars = [name, varlabel, value, vallabel]
        mdata = Metadata()
        
        curs = spssdata.Spssdata(sourcevars)
        for case in curs:
            mdata.varlabel(case[0], case[1])
            mdata.vallabels(case[0], case[2], case[3])
        curs.CClose()
        
        spss.Submit("""
        DATASET ACTIVATE TARGET.
        DATASET CLOSE METADATA.
        """)
        vardict = spssaux.VariableDict()
        for v in vardict.variables:
            mdata.copy(v)

    (incidentally, the code (<>) mechanism of your ckEditor does not behave for me ... using Pale Moon variant of Firefox)

    Hi Jon,

    Without any success, I have attempted to modify the python module pasted above to account for variable attributes assigned to columns adjacent to those already existing in my metadata dataset. This is not surprising, since I am no Python programmer.

    Could you or anyone else help me to augment class Metadata and def copyMetadata to account for the additional attributes of 'attribute name' and 'attribute value'? Perhaps some direction in producing the syntax:

    VARIABLE ATTRIBUTE VARIABLES=@18876 ATTRIBUTE=test('1').

    where '@18876' is the variable name,

    'test' is the attribute name, and

    '1' is the attribute value

    --all to be found in separate columns of the metadata dataset to be applied to the dictionary of the active dataset.

  • David VW
    David VW
    19 Posts

    Re: Problem & SETSMACRO issue

    ‏2014-07-09T18:39:24Z  
    • David VW
    • ‏2014-07-03T17:36:25Z

    Hi Jon,

    Without any success, I have attempted to modify the python module pasted above to account for variable attributes assigned to columns adjacent to those already existing in my metadata dataset. This is not surprising, since I am no Python programmer.

    Could you or anyone else help me to augment class Metadata and def copyMetadata to account for the additional attributes of 'attribute name' and 'attribute value'? Perhaps some direction in producing the syntax:

    VARIABLE ATTRIBUTE VARIABLES=@18876 ATTRIBUTE=test('1').

    where '@18876' is the variable name,

    'test' is the attribute name, and

    '1' is the attribute value

    --all to be found in separate columns of the metadata dataset to be applied to the dictionary of the active dataset.

    Bumping this ticket ... seeking Python code support (see previous)

     

    Thanks

  • JonPeck
    JonPeck
    343 Posts

    Re: Problem & SETSMACRO issue

    ‏2014-07-10T02:56:21Z  
    • David VW
    • ‏2014-07-09T18:39:24Z

    Bumping this ticket ... seeking Python code support (see previous)

     

    Thanks

    David,

    Could you state exactly what you want to do?  And have you considered using APPLY DICTIONARY to copy the metadata.

  • David VW
    David VW
    19 Posts

    Re: Problem & SETSMACRO issue

    ‏2014-07-14T15:08:04Z  
    • JonPeck
    • ‏2014-07-10T02:56:21Z

    David,

    Could you state exactly what you want to do?  And have you considered using APPLY DICTIONARY to copy the metadata.

    Hi Jon,

    In my second post on this thread, I have described my problem, what I want to do, and included a module that I use today for copying metadata programmatically from one dataset to another.

    As I describe in my subsequent post, I am not at all clear on how to call custom attributes using this module and a similar data arrangement.

    Could you please read my posts above? I think that I have provided enough detail to help you to help me. If not, then please ask me any specific question you might have.

    APPLY DICTIONARY does not seem to pertain, since my metadata are stored as data (see second post) and applied to the dictionary. Aside from that, the Python module works great, and I only need to add a method to read and copy the custom attributes. I would much rather build out the existing method. I have come up with the following so far, which seems to be on the right path but not at all viable, since I don't know enough about Python or how SPSS stores custom attributes:

    # Collect metadata from one dataset and apply to matching variables in another.
    # Only intended for numeric variables
    # Both datasets should have a dataset name

    import spss, spssaux, spssdata

    class Metadata(object):
        """structures to hold metadata"""
        
        def __init__(self):
            self.data = {}
            
        def varlabel(self, name, label):
            name = name.lower().rstrip()
            if not name in self.data:
                self.data[name] = {}
                self.data[name]['vallabels'] = {}
                self.data[name]['varattr'] = {}
            label = label.rstrip()
            if not label == "":
                self.data[name]['label'] = label
            
        def vallabels(self, name, value, label):
            name = name.lower().rstrip()
            if not value is None:
                self.data[name]['vallabels'][value] = label.rstrip()
            
        def varattr(self, name, attrvalue, attrlabel):
            name = name.lower().rstrip()
            if not attrvalue is None:
                self.data[name]['varattr'][attrvalue] = attrlabel.rstrip()
            
        def copy(self, name):
            name = name.lower()
            if not name in self.data:
                return
            varlabel = self.data[name].get('label', "")
            if not varlabel == "":
                spss.Submit("""VARIABLE LABELS %(name)s "%(varlabel)s".""" % locals())
            vallabels = [str(val) + ' "%s"' % label for val, label in self.data[name]['vallabels'].items()]
            if len(vallabels) > 0:
                vlstr = " ".join(vallabels)
                spss.Submit(""" VALUE LABELS %(name)s  %(vlstr)s """ % locals())
            varattr = self.data[name].get('attrlabel', "")
            if not varlabel == "":
                spss.Submit(""" VARIABLE ATTRIBUTE VARIABLES=%(name)s ATTRIBUTE="%(varattr)s".""" % locals())

    def copyMetadata(target, name, varlabel, value, vallabel, varattr, attrvalue):
        """Read variables containing metadata from active dataset and apply to another dataset.
        
        Target is the dataset name whose variable metadata will be updated.
        In the source (active) dataset,
         name is the variable containing variable names
         varlabel contains variable labels
         value and vallabel contain value/value label pairs.  (Last entry for a variable wins)
        
        Metadata for variables not in the target dataset are ignored."""
        

        sourcevars = [name, varlabel, value, vallabel, varattr, attrvalue]
        mdata = Metadata()
        
        curs = spssdata.Spssdata(sourcevars)
        for case in curs:
            mdata.varlabel(case[0], case[1])
            mdata.vallabels(case[0], case[2], case[3])
            mdata.varattr(case[0], case[2], case[3])
        curs.CClose()
        
        spss.Submit("""
        DATASET ACTIVATE TARGET.
        DATASET CLOSE METADATA.
        """)
        vardict = spssaux.VariableDict()
        for v in vardict.variables:
            mdata.copy(v)

    thanks

  • JonPeck
    JonPeck
    343 Posts

    Re: Problem & SETSMACRO issue

    ‏2014-07-14T19:05:25Z  
    • David VW
    • ‏2014-07-14T15:08:04Z

    Hi Jon,

    In my second post on this thread, I have described my problem, what I want to do, and included a module that I use today for copying metadata programmatically from one dataset to another.

    As I describe in my subsequent post, I am not at all clear on how to call custom attributes using this module and a similar data arrangement.

    Could you please read my posts above? I think that I have provided enough detail to help you to help me. If not, then please ask me any specific question you might have.

    APPLY DICTIONARY does not seem to pertain, since my metadata are stored as data (see second post) and applied to the dictionary. Aside from that, the Python module works great, and I only need to add a method to read and copy the custom attributes. I would much rather build out the existing method. I have come up with the following so far, which seems to be on the right path but not at all viable, since I don't know enough about Python or how SPSS stores custom attributes:

    # Collect metadata from one dataset and apply to matching variables in another.
    # Only intended for numeric variables
    # Both datasets should have a dataset name

    import spss, spssaux, spssdata

    class Metadata(object):
        """structures to hold metadata"""
        
        def __init__(self):
            self.data = {}
            
        def varlabel(self, name, label):
            name = name.lower().rstrip()
            if not name in self.data:
                self.data[name] = {}
                self.data[name]['vallabels'] = {}
                self.data[name]['varattr'] = {}
            label = label.rstrip()
            if not label == "":
                self.data[name]['label'] = label
            
        def vallabels(self, name, value, label):
            name = name.lower().rstrip()
            if not value is None:
                self.data[name]['vallabels'][value] = label.rstrip()
            
        def varattr(self, name, attrvalue, attrlabel):
            name = name.lower().rstrip()
            if not attrvalue is None:
                self.data[name]['varattr'][attrvalue] = attrlabel.rstrip()
            
        def copy(self, name):
            name = name.lower()
            if not name in self.data:
                return
            varlabel = self.data[name].get('label', "")
            if not varlabel == "":
                spss.Submit("""VARIABLE LABELS %(name)s "%(varlabel)s".""" % locals())
            vallabels = [str(val) + ' "%s"' % label for val, label in self.data[name]['vallabels'].items()]
            if len(vallabels) > 0:
                vlstr = " ".join(vallabels)
                spss.Submit(""" VALUE LABELS %(name)s  %(vlstr)s """ % locals())
            varattr = self.data[name].get('attrlabel', "")
            if not varlabel == "":
                spss.Submit(""" VARIABLE ATTRIBUTE VARIABLES=%(name)s ATTRIBUTE="%(varattr)s".""" % locals())

    def copyMetadata(target, name, varlabel, value, vallabel, varattr, attrvalue):
        """Read variables containing metadata from active dataset and apply to another dataset.
        
        Target is the dataset name whose variable metadata will be updated.
        In the source (active) dataset,
         name is the variable containing variable names
         varlabel contains variable labels
         value and vallabel contain value/value label pairs.  (Last entry for a variable wins)
        
        Metadata for variables not in the target dataset are ignored."""
        

        sourcevars = [name, varlabel, value, vallabel, varattr, attrvalue]
        mdata = Metadata()
        
        curs = spssdata.Spssdata(sourcevars)
        for case in curs:
            mdata.varlabel(case[0], case[1])
            mdata.vallabels(case[0], case[2], case[3])
            mdata.varattr(case[0], case[2], case[3])
        curs.CClose()
        
        spss.Submit("""
        DATASET ACTIVATE TARGET.
        DATASET CLOSE METADATA.
        """)
        vardict = spssaux.VariableDict()
        for v in vardict.variables:
            mdata.copy(v)

    thanks

    David,

    Without getting into your code, here is an example of transferring case values from one dataset into attributes for corresponding variables in another.

    Here is the setup code:

    * target variables.
    data list list/var1 to var5(5f1).
    begin data
    1 2 3 4 5
    end data.
    dataset name variables.

    * attributes dataset.
    data list list /VARIABLE(a8) ATTRIBUTE1(f1) ATTRIBUTE2(f1) ATTRIBUTE3 (a8).
    begin data
    var1             2                         1                           string1
    var2            2                          1                           string2
    var3            4                          0                           string1
    var4            4                          1                           string2
    var5            3                          0                           string3
    end data
    dataset name attributes.

    Here is the Python code to do this.  Does this do what you want?

    begin program.
    import spss, spssdata, spssaux

    attrdict = {}
    curs = spssdata.Spssdata()
    for case in curs:
        attrdict[case[0].rstrip()] = case[1:4]
    curs.CClose()
    spss.Submit("dataset activate variables")
    vardict = spssaux.VariableDict()
    for v in attrdict.keys():
        if v in vardict:
            vattrdict = dict(zip(["ATTRIBUTE1", "ATTRIBUTE2", "ATTRIBUTE3"],
                attrdict[v]))
            vardict[v].Attributes = vattrdict
    end program.

     

    Updated on 2014-07-14T19:08:08Z at 2014-07-14T19:08:08Z by JonPeck
  • David VW
    David VW
    19 Posts

    Re: Problem & SETSMACRO issue

    ‏2014-07-14T19:19:47Z  
    • JonPeck
    • ‏2014-07-14T19:05:25Z

    David,

    Without getting into your code, here is an example of transferring case values from one dataset into attributes for corresponding variables in another.

    Here is the setup code:

    * target variables.
    data list list/var1 to var5(5f1).
    begin data
    1 2 3 4 5
    end data.
    dataset name variables.

    * attributes dataset.
    data list list /VARIABLE(a8) ATTRIBUTE1(f1) ATTRIBUTE2(f1) ATTRIBUTE3 (a8).
    begin data
    var1             2                         1                           string1
    var2            2                          1                           string2
    var3            4                          0                           string1
    var4            4                          1                           string2
    var5            3                          0                           string3
    end data
    dataset name attributes.

    Here is the Python code to do this.  Does this do what you want?

    begin program.
    import spss, spssdata, spssaux

    attrdict = {}
    curs = spssdata.Spssdata()
    for case in curs:
        attrdict[case[0].rstrip()] = case[1:4]
    curs.CClose()
    spss.Submit("dataset activate variables")
    vardict = spssaux.VariableDict()
    for v in attrdict.keys():
        if v in vardict:
            vattrdict = dict(zip(["ATTRIBUTE1", "ATTRIBUTE2", "ATTRIBUTE3"],
                attrdict[v]))
            vardict[v].Attributes = vattrdict
    end program.

     

    Yes, this does exactly what I want ... I'd just like to incorporate it into my module by defining a variable in class metadata for use in def copyMetadata within my above code ... I attempted this under:

    def varattr(self, name, attrvalue, attrlabel):

    I should be able to get somewhere on this myself using your implementation example, but if you are willing to help me translate your code into the code paradigm above, it would likely be a huge time saver for me (i.e., the time cost to me would likely greatly exceed the time cost to you).

    That said, I am willing to take a stab at it myself at the risk of reviving this thread later ;)

    thanks!

  • JonPeck
    JonPeck
    343 Posts

    Re: Problem & SETSMACRO issue

    ‏2014-07-15T12:30:37Z  
    • David VW
    • ‏2014-07-14T19:19:47Z

    Yes, this does exactly what I want ... I'd just like to incorporate it into my module by defining a variable in class metadata for use in def copyMetadata within my above code ... I attempted this under:

    def varattr(self, name, attrvalue, attrlabel):

    I should be able to get somewhere on this myself using your implementation example, but if you are willing to help me translate your code into the code paradigm above, it would likely be a huge time saver for me (i.e., the time cost to me would likely greatly exceed the time cost to you).

    That said, I am willing to take a stab at it myself at the risk of reviving this thread later ;)

    thanks!

    I'll take a look at this.

  • JonPeck
    JonPeck
    343 Posts

    Re: Problem & SETSMACRO issue

    ‏2014-07-21T12:55:38Z  
    • JonPeck
    • ‏2014-07-15T12:30:37Z

    I'll take a look at this.

    David,

    It will be a few more days before I can look at this as I need to finish a project first.

  • David VW
    David VW
    19 Posts

    Re: Problem & SETSMACRO issue

    ‏2014-07-22T14:32:33Z  
    • JonPeck
    • ‏2014-07-21T12:55:38Z

    David,

    It will be a few more days before I can look at this as I need to finish a project first.

    That will be great, Jon. I'll look forward to it.

  • JonPeck
    JonPeck
    343 Posts

    Re: Problem & SETSMACRO issue

    ‏2014-07-22T19:44:23Z  
    • David VW
    • ‏2014-07-22T14:32:33Z

    That will be great, Jon. I'll look forward to it.

    Try the attached file.  Note that the invoking signature has changed in order to accommodate the attributes variables, which are given as a list to the last argument.  The number and names for the attributes can be whatever you want.

    The test file constructs a metadata dataset, a target dataset, and runs the transfer code.  I noticed that the dataset names are hardwired in your code even though the target dataset name is a parameter.

     

    Attachments

  • David VW
    David VW
    19 Posts

    Re: Problem & SETSMACRO issue

    ‏2014-07-23T17:08:01Z  
    • JonPeck
    • ‏2014-07-22T19:44:23Z

    Try the attached file.  Note that the invoking signature has changed in order to accommodate the attributes variables, which are given as a list to the last argument.  The number and names for the attributes can be whatever you want.

    The test file constructs a metadata dataset, a target dataset, and runs the transfer code.  I noticed that the dataset names are hardwired in your code even though the target dataset name is a parameter.

     

    Hi Jon,

    Many thanks!

    I belive that this will work, but I will reply back on this thread if I have questions.

    I removed the spss.Submit() from the code ... this is a relic that I had added long ago before the dataset names were accounted for by the Py code. This does not seem to have added or detracted from the result historically. Thanks for pointing that out, as I hadn't noticed.