Hi,
I am looking for a string "2^1", optionally with whitespaces (so simply using char.index will soon become l-o-n-g)
Target variable is a binary variable named "isPresent".
Currently I do:
spssinc trans result = helper type=100 /formula "re.findall(r'.*2\s*\^\s*1.*', Address)". /* I cannot use scratch "#result"
compute isPresent = char.length(helper) gt 0.
add files /file = * /drop = helper.
Can I make this even shorter, without the helper var? This does not work:
spssinc trans result = isPresent type=0 /formula "lambda Address: bool(re.findall(r'.*2\s*\^\s*1.*', Address))". 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? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
You have to create the helper variable,
because spssinc trans does not run within the Statistics transformation
system. However, you could compute the isPresent variable directly
as the result variable in spss trans and eliminate the compute and add
files commands. You would probably have to do that with a begin program
block to define a function that can be referenced in the formula subcommand.
Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Albert-Jan Roskam <[hidden email]> To: [hidden email], Date: 07/25/2013 04:19 AM Subject: [SPSSX-L] spssinc trans question Sent by: "SPSSX(r) Discussion" <[hidden email]> Hi, I am looking for a string "2^1", optionally with whitespaces (so simply using char.index will soon become l-o-n-g) Target variable is a binary variable named "isPresent". Currently I do: spssinc trans result = helper type=100 /formula "re.findall(r'.*2\s*\^\s*1.*', Address)". /* I cannot use scratch "#result" compute isPresent = char.length(helper) gt 0. add files /file = * /drop = helper. Can I make this even shorter, without the helper var? This does not work: spssinc trans result = isPresent type=0 /formula "lambda Address: bool(re.findall(r'.*2\s*\^\s*1.*', Address))". 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? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Thank you. I might indeed define a function "myFunc". If I am using a complex regex, or if I have lots of cases, where should I define a compiled regex?
Is "myFunc" called once for each record? If so, then I should define the regex outside the function.
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? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
I doubt that would notice the overhead
of recompiling the regex, but spssinc trans has an initial subcommand that
can be used to initialize a class and set up the function to be called
for each case.
Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Albert-Jan Roskam <[hidden email]> To: Jon K Peck/Chicago/IBM@IBMUS, Cc: "[hidden email]" <[hidden email]> Date: 07/25/2013 07:19 AM Subject: Re: [SPSSX-L] spssinc trans question Thank you. I might indeed define a function "myFunc". If I am using a complex regex, or if I have lots of cases, where should I define a compiled regex? Is "myFunc" called once for each record? If so, then I should define the regex outside the function. 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? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From: Jon K Peck <[hidden email]> To: Albert-Jan Roskam <[hidden email]> Cc: [hidden email] Sent: Thursday, July 25, 2013 2:27 PM Subject: Re: [SPSSX-L] spssinc trans question You have to create the helper variable, because spssinc trans does not run within the Statistics transformation system. However, you could compute the isPresent variable directly as the result variable in spss trans and eliminate the compute and add files commands. You would probably have to do that with a begin program block to define a function that can be referenced in the formula subcommand. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Albert-Jan Roskam <[hidden email]> To: [hidden email], Date: 07/25/2013 04:19 AM Subject: [SPSSX-L] spssinc trans question Sent by: "SPSSX(r) Discussion" <[hidden email]> Hi, I am looking for a string "2^1", optionally with whitespaces (so simply using char.index will soon become l-o-n-g) Target variable is a binary variable named "isPresent". Currently I do: spssinc trans result = helper type=100 /formula "re.findall(r'.*2\s*\^\s*1.*', Address)". /* I cannot use scratch "#result" compute isPresent = char.length(helper) gt 0. add files /file = * /drop = helper. Can I make this even shorter, without the helper var? This does not work: spssinc trans result = isPresent type=0 /formula "lambda Address: bool(re.findall(r'.*2\s*\^\s*1.*', Address))". 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? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Free forum by Nabble | Edit this page |