Hi All,
I'm a new SPSS user coming from a Stata environment. I want to refer to all variables in my set with suffix _A21 (for example) in order to quickly run frequencies, recodes, etc etc. In the stata coding environment I would input command *_A21 which would enable to command on all variables ending with _A21 Is there any equivalent in SPSS or am I just going to have to tediously write each variable out? Thanks, russell |
If the variables are contiguous in the
file, you can use the TO construct.
For a more general mechanism, if you install the Python Essentials and the SPSSINC SELECT VARIABLES extension command (Utilities > Define Variable Macro) from the SPSS Community website (www.ibm.com/developerworks/spssdevcentral), you can use it to define a macro that refers to a set of variables selected based on regular expressions, variable type, measurement level etc and use that. In your example, this might be SPSSINC SELECT VARIABLES MACRONAME="!A21" /PROPERTIES PATTERN = "*_A21$". and then, say, for example, DESCRIPTIVES VARIABLES=!A21. The regular expression here selects all names that end with _A21. After running the SELECT command, the symbol !A21 expands to the list of matching names wherever it is used. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: russellsimco <[hidden email]> To: [hidden email], Date: 06/04/2013 01:09 PM Subject: [SPSSX-L] Refer to multiple variables using common suffix Sent by: "SPSSX(r) Discussion" <[hidden email]> Hi All, I'm a new SPSS user coming from a Stata environment. I want to refer to all variables in my set with suffix _A21 (for example) in order to quickly run frequencies, recodes, etc etc. In the stata coding environment I would input command *_A21 which would enable to command on all variables ending with _A21 Is there any equivalent in SPSS or am I just going to have to tediously write each variable out? Thanks, russell -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Refer-to-multiple-variables-using-common-suffix-tp5720548.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 |
In reply to this post by russellsimco
Hi,
If the variables are contiguous in the file you can use TO: v1_a21 TO v1000_a21. If not, you could do (untested): begin program. import spss, spssaux varnames = " ".join([v.VariableName for v in spssaux.VariableDict(pattern="(?i)\w+_A21")]) spss.SetMacroValue("!a21vars", varnames) end program. Then you can refer to those vars in your code as !a21vars, which is a macro. the regular expression pattern will match regardless of casing (?i), which may already be part of the variabledict class (I don't recall). Regards, Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ----- Original Message ----- > From: russellsimco <[hidden email]> > To: [hidden email] > Cc: > Sent: Tuesday, June 4, 2013 4:08 PM > Subject: [SPSSX-L] Refer to multiple variables using common suffix > > Hi All, > > I'm a new SPSS user coming from a Stata environment. > > I want to refer to all variables in my set with suffix _A21 (for example) in > order to quickly run frequencies, recodes, etc etc. > > In the stata coding environment I would input command *_A21 which would > enable to command on all variables ending with _A21 > > Is there any equivalent in SPSS or am I just going to have to tediously > write each variable out? > > Thanks, > > russell > > > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/Refer-to-multiple-variables-using-common-suffix-tp5720548.html > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > 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 |
In reply to this post by Jon K Peck
Thanks for your help, I'll try this solution...good to know that there are user-developped add-ons for spss as well (as stata). On Tue, Jun 4, 2013 at 3:38 PM, Jon K Peck [via SPSSX Discussion] <[hidden email]> wrote:
If the variables are contiguous in the
file, you can use the TO construct.
For a more general mechanism, if you install the Python Essentials and the SPSSINC SELECT VARIABLES extension command (Utilities > Define Variable Macro) from the SPSS Community website (www.ibm.com/developerworks/spssdevcentral), you can use it to define a macro that refers to a set of variables selected based on regular expressions, variable type, measurement level etc and use that. In your example, this might be SPSSINC SELECT VARIABLES MACRONAME="!A21" /PROPERTIES PATTERN = "*_A21$". and then, say, for example, DESCRIPTIVES VARIABLES=!A21. The regular expression here selects
all names that end with _A21. After running the SELECT command, the
symbol !A21 expands to the list of matching names wherever it is used. [hidden email]Jon Peck (no "h") aka Kim Senior Software Engineer, IBM phone: <a href="tel:720-342-5621" value="+17203425621" target="_blank">720-342-5621 From: russellsimco <[hidden email]> To: [hidden email], Date:
06/04/2013 01:09 PM
Sent by:
"SPSSX(r)
Discussion" <[hidden email]>
Subject: [SPSSX-L] Refer to multiple variables using common suffix Hi All, I'm a new SPSS user coming from a Stata environment. I want to refer to all variables in my set with suffix _A21 (for example) in order to quickly run frequencies, recodes, etc etc. In the stata coding environment I would input command *_A21 which would enable to command on all variables ending with _A21 Is there any equivalent in SPSS or am I just going to have to tediously write each variable out? Thanks, russell -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Refer-to-multiple-variables-using-common-suffix-tp5720548.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Refer-to-multiple-variables-using-common-suffix-tp5720548p5720568.html
View this message in context: Re: Refer to multiple variables using common suffix Sent from the SPSSX Discussion mailing list archive at Nabble.com. |
The pattern is any variable name ending with "_A21", right? Shouldn't that be
pattern=".*_A21$" ? |
Sorry, Ruben is correct. "."
matches any character, so ".*" matches any string of characters.
Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Ruben Geert van den Berg <[hidden email]> To: [hidden email], Date: 06/05/2013 01:36 AM Subject: Re: [SPSSX-L] Refer to multiple variables using common suffix Sent by: "SPSSX(r) Discussion" <[hidden email]> The pattern is /any variable name ending with "_A21"/, right? Shouldn't that be pattern=".*_A21$" ? -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Refer-to-multiple-variables-using-common-suffix-tp5720548p5720575.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 |
Free forum by Nabble | Edit this page |