Referring to custom attributes in Syntax

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Referring to custom attributes in Syntax

jenmabrey
Has anyone found a way to point to custom attributes of variables in Syntax?  In particular, I'm looking to select cases by using the custom attribute assignments.  I need to pull data into a file, use the custom attributes of variables to assign aliases or generic names, then set up an alias-based syntax that can be used across multiple data sets.  Any help or suggestions would be greatly appreciated!
This email message is intended for use only by the person(s) or entity to which it is addressed and may contain privileged or confidential information owned by rsc THE QUALITY MEASUREMENT COMPANY. Any unauthorized use or disclosure of this information is strictly prohibited. Copyright 2008 rsc. All rights reserved

====================To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Referring to custom attributes in Syntax

Peck, Jon
Custom attributes are well suited for the purpose you described.

You can create and display custom attributes in standard syntax (and, with SPSS 16, have them appear in the Data Editor Variable View), but to use them in program logic, you would use programmability.

Here is an example using the cars.sav dataset shipped with SPSS.

First, define an attribute named "important" for a few variables and assign it a value.

VARIABLE ATTRIBUTE VARIABLES=accel ATTRIBUTE=importance('high').
VARIABLE ATTRIBUTE VARIABLES=cylinder ATTRIBUTE=importance('medium').
VARIABLE ATTRIBUTE VARIABLES=engine ATTRIBUTE=importance('high').

Display the variable information, including attributes.
DISPLAY DICTIONARY.

Next, run a program that finds the variables that have a high value for importance and print the name.

begin program.
import spss, spssaux
vardict = spssaux.VariableDict()
for v in vardict:
  attributes = v.Attributes
  if attributes.get("importance", "low") == "high":
    print v, "important"
end program.

In this program, Python first gets a variable dictionary (vardict).
Next, it loops over the variables in the dataset and gets their custom attributes.
Next, it uses the get method on the attribute dictionary to see if the importance attribute has a value of "high".  If the variable's attribute dictionary does not have an importance attribute, the get function returns a default value of "low".
Finally, the variable's name and the literal "important" is printed.

This example will work with SPSS 14 and later.  It requires Python and the programmability plugin plus the spssaux supplementary module.  See SPSS Developer Central, www.spss.com/devcentral for these materials except for Python itself.

HTH,
Jon Peck



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Mabrey, Jennifer L.
Sent: Tuesday, May 27, 2008 5:03 AM
To: [hidden email]
Subject: [SPSSX-L] Referring to custom attributes in Syntax

Has anyone found a way to point to custom attributes of variables in Syntax?  In particular, I'm looking to select cases by using the custom attribute assignments.  I need to pull data into a file, use the custom attributes of variables to assign aliases or generic names, then set up an alias-based syntax that can be used across multiple data sets.  Any help or suggestions would be greatly appreciated!
This email message is intended for use only by the person(s) or entity to which it is addressed and may contain privileged or confidential information owned by rsc THE QUALITY MEASUREMENT COMPANY. Any unauthorized use or disclosure of this information is strictly prohibited. Copyright 2008 rsc. All rights reserved

=======
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD