spssinc trans

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

spssinc trans

oggesjolin
This post was updated on .
Hi!

I'm trying to split a string variable containing numbers (1-99) separated by a ";" into 10 new variables numbered "newvar_1","newvar_2" (as numerics) and so on.

I have this:

SPSSINC TRANS RESULT = mqTest_1 TO mqTest_10  TYPE=0
  /FORMULA "string.split(qTest,';')".

Works fine as long there are no empty strings in qTest, at which point the SPSSINC TRANS command seems to just stop? Am I missing something here?

Kind regards
/Ogge


Reply | Threaded
Open this post in threaded view
|

Re: spssinc trans

Andy W
My version wants you to specify that the resulting variables are strings, but otherwise works:

******************************.
DATA LIST FREE / qTest (A20).
BEGIN DATA
"1;2;3;4"
""
"5;6;7;8"
END DATA.
DATASET NAME Test.


SPSSINC TRANS RESULT = mqTest_1 TO mqTest_10  TYPE=1
  /FORMULA "string.split(qTest,';')".
******************************.

IIRC, there were older versions of TRANS that had this problem, so updating the plug-in may solve the problem.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: spssinc trans

oggesjolin
OK, thanks Andy, I'll check for updates.

Reply | Threaded
Open this post in threaded view
|

Re: spssinc trans

Jon K Peck
In reply to this post by Andy W
SPSSINC TRANS lets you specify the type of the result variables, but it expects you to provide values consistent with that type.
Here's an example that includes that conversion.  You first define the function and then use it in the SPSSINC TRANS call.  The FORMULA subcommand only allows very simple Python code to be specified directly, but the actual function to be called can be arbitrarily complex.
The only difference in this case is the conversion of the split results to numeric.

begin program.
import string
def f(x):
    return [float(item) for item in string.split(x, ";")]
end program.

SPSSINC TRANS RESULT = mqTest_1 TO mqTest_10  TYPE=0
  /FORMULA "f(x)".


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Andy W <[hidden email]>
To:        [hidden email]
Date:        06/03/2015 05:27 AM
Subject:        Re: [SPSSX-L] spssinc trans
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




My version wants you to specify that the resulting variables are strings, but
otherwise works:

******************************.
DATA LIST FREE / qTest (A20).
BEGIN DATA
"1;2;3;4"
""
"5;6;7;8"
END DATA.
DATASET NAME Test.


SPSSINC TRANS RESULT = mqTest_1 TO mqTest_10  TYPE=1
 /FORMULA "string.split(qTest,';')".
******************************.

IIRC, there were older versions of TRANS that had this problem, so updating
the plug-in may solve the problem.



-----
Andy W
[hidden email]
http://andrewpwheeler.wordpress.com/
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/spssinc-trans-tp5729734p5729735.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