search argument and return the nth name

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

search argument and return the nth name

Pele
Hi SPSS user,

Can someone tell me if SPSS has a function (similar to SAS %scan) that can search an argument (or string of variable names separated by ' ') and return the nth name.  Below is an example of what I am trying to do using SAS code.

%do i = 1 %to 5;
%let varname = %scan(&varlist,&i, ' ');
%end.

Thanks in advance for your help.
Reply | Threaded
Open this post in threaded view
|

Re: search argument and return the nth name

Jon K Peck

See below.
Jon Peck
SPSS, an IBM Company
[hidden email]
312-651-3435



From: Pele <[hidden email]>
To: [hidden email]
Date: 11/25/2009 08:35 AM
Subject: [SPSSX-L] search argument and return the nth name
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Hi SPSS user,

Can someone tell me if SPSS has a function (similar to SAS %scan) that can
search an argument (or string of variable names separated by ' ') and return
the nth name.  Below is an example of what I am trying to do using SAS code.

%do i = 1 %to 5;
%let varname = %scan(&varlist,&i, ' ');
%end.

Thanks in advance for your help.


>>>SPSS does not have a built-in function like this, although you could write a DO with the index and substr functions.

Here is a way to do it with the SPSSINC TRANS extension command, which requires the Python programmability plugin and at least Version 17.  The extension command, which also includes a dialog box interface, and the plugin can be downloaded from SPSS Developer Central, www.spss.com/devcentral.

SPSSINC TRANS RESULT=v1 v2 v3 v4 v5 TYPE=20 20 20 20 20
/FORMULA string.split(str).

This creates five new variables, v1, ... v5, each a string of length 20, by applying the specified formula to the string variable named str.  If there are fewer values found than the number of variables, the result will be blank.  If there are more, it is an error.  SPSSINC TRANS can apply any Python function to variables in the SPSS case data.

HTH,
Jon Peck
--
View this message in context:
http://old.nabble.com/search-argument-and-return-the-nth-name-tp26512871p26512871.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


Reply | Threaded
Open this post in threaded view
|

Re: search argument and return the nth name

Pele
Hi Jon,

Thanks for the suggestion - will give it a go.

Jon K Peck wrote
See below.
Jon Peck
SPSS, an IBM Company
peck@us.ibm.com
312-651-3435



From:
Pele <drdionc@yahoo.com>
To:
SPSSX-L@LISTSERV.UGA.EDU
Date:
11/25/2009 08:35 AM
Subject:
[SPSSX-L] search argument and return the nth name
Sent by:
"SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>



Hi SPSS user,

Can someone tell me if SPSS has a function (similar to SAS %scan) that can
search an argument (or string of variable names separated by ' ') and
return
the nth name.  Below is an example of what I am trying to do using SAS
code.

%do i = 1 %to 5;
%let varname = %scan(&varlist,&i, ' ');
%end.

Thanks in advance for your help.

>>>SPSS does not have a built-in function like this, although you could
write a DO with the index and substr functions.

Here is a way to do it with the SPSSINC TRANS extension command, which
requires the Python programmability plugin and at least Version 17.  The
extension command, which also includes a dialog box interface, and the
plugin can be downloaded from SPSS Developer Central,
www.spss.com/devcentral.

SPSSINC TRANS RESULT=v1 v2 v3 v4 v5 TYPE=20 20 20 20 20
/FORMULA string.split(str).

This creates five new variables, v1, ... v5, each a string of length 20,
by applying the specified formula to the string variable named str.  If
there are fewer values found than the number of variables, the result will
be blank.  If there are more, it is an error.  SPSSINC TRANS can apply any
Python function to variables in the SPSS case data.

HTH,
Jon Peck
--
View this message in context:
http://old.nabble.com/search-argument-and-return-the-nth-name-tp26512871p26512871.html

Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (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