Basic Recode syntax not creating new Variable

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

Basic Recode syntax not creating new Variable

Blankdots
As part of a larger program, I'm recoding some variables. The Syntax should explain the exact nature of what i'm trying to do.

However, the code did not run in my larger program so to troubleshoot the issue I created a very small program to run the basic recode syntax.

The program runs without any error messages. However when I open the spss file, there is no new variable with my recoded data.

To make sure I didn't make any mistakes in my coding. I pasted the SYNTAX straight from spss into python.

Here is the python code.

from __future__ import with_statement

def main():
    pass

if __name__ == '__main__':
    main()

import spss
import SpssClient
import spssaux

spss.Submit (r"""GET FILE='E:\Work\Masters\SC177 SPS Work\GeneTest.Sav'.""")

spss.Submit(r"""RECODE CAST.1564010_at (Lowest thru 6.8294=1) (6.8295 thru Highest=2) INTO CAST.1564010_at_group.
EXECUTE. """)
Reply | Threaded
Open this post in threaded view
|

Re: Basic Recode syntax not creating new Variable

Art Kendall
What happens if you completely remove it from python and try just the SPSS portion?
GET FILE='E:\Work\Masters\SC177 SPS Work\GeneTest.Sav'.
RECODE CAST.1564010_at
  (Lowest thru 6.8294=1) (6.8295 thru Highest=2)
  INTO CAST.1564010_at_group.


Try this syntax in a new instance of SPSS.

new file.
input program.
   loop id = 1 to 25.
         compute CAST.1564010_at = rv.normal(6.8294,.0001).
      end case.
   end loop.
   end file.
end input program.
formats CAST.1564010_at (f19.16).
RECODE CAST.1564010_at (Lowest thru 6.8294=1) (6.8295 thru
Highest=2) INTO CAST.1564010_at_group.
sort cases by CAST.1564010_at.
list.




Art Kendall
Social Research Consultants
On 1/26/2013 8:32 AM, Blankdots wrote:
RECODE CAST.1564010_at (Lowest thru 6.8294=1) (6.8295 thru
Highest=2) INTO CAST.1564010_at_group.

===================== 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Basic Recode syntax not creating new Variable

Blankdots
If i try to run the original SPSS syntax inside spss it runs fine. A new column with the variable appears.
Reply | Threaded
Open this post in threaded view
|

Re: Basic Recode syntax not creating new Variable

Blankdots
In reply to this post by Art Kendall
Your Syntax works in creating a new group that has the recoded variables. However it changes the original column values which is not what I want.

Something really wierd is happening now. If I try to recode via the graphical interface it recodes and creates a new variable. However if i try to paste the syntax into a new syntax window and run it nothing happens. its the same syntax that is run by the GUI, so why its not working is baffling me.  
Reply | Threaded
Open this post in threaded view
|

Re: Basic Recode syntax not creating new Variable

Blankdots
In reply to this post by Blankdots
I ran some more tests. I can run Kaplan Meier analysis and Descriptives analysis by pasting into a new syntax and running. But for some reason when I paste a recode into a new syntax window it doesn't work. No error messages when I press run, but it doesn't forward me to output window, or create a new variable.
Reply | Threaded
Open this post in threaded view
|

Re: Basic Recode syntax not creating new Variable

Jon K Peck
I think after you run from the syntax window you will see "pending transformations" in the status bar.  Run an EXECUTE command or use Transform > Run Pending Transformations.


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




From:        Blankdots <[hidden email]>
To:        [hidden email],
Date:        01/26/2013 06:27 PM
Subject:        Re: [SPSSX-L] Basic Recode syntax not creating new Variable
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




I ran some more tests. I can run Kaplan Meier analysis and Descriptives
analysis by pasting into a new syntax and running. But for some reason when
I paste a recode into a new syntax window it doesn't work. No error messages
when I press run, but it doesn't forward me to output window, or create a
new variable.



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Basic-Recode-syntax-not-creating-new-Variable-tp5717713p5717727.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: Basic Recode syntax not creating new Variable

Blankdots

If I click the paste button  from the graphic interface then run it. It sometimes works. It seems to work the first time. If i then delete the recoded variable and try it again it doesn't work. 'EXECUTE' appears in the output but the actual preceeding code is not run. If i can explain...

RECODE CAST.1564010_at (Lowest thru 6.8294=1) (6.8295 thru Highest=2) INTO CAST.1564010_at_group.
EXECUTE.
EXECUTE.
EXECUTE.

The first time it works. I then delete the recoded variable and try running again. I go back to the syntax window run it again and only excute appears in output.

Why It doesn't work for python
If I copy the code from the original paste, THEN open a NEW syntax window and try to run it. It never works. The "Run pending transformations" is greyed out after I run. Also at the bottom it says IBM SPSS... is ready. If I click the play button multiple times, it just clicks, but nothing actually happens. There is no error message. Also the Output viewer doesn't display any code as being run, not even an Execute.

This seems to only be affecting the recode function and only in the syntax viewer. As I've said previously, If i try descriptives function or Km function, I can simply paste the code into a new syntax viewer and run it without issues.

I think once this is fixed, it will work in python.  If it helps at all, I'm running spss version 20.

Reply | Threaded
Open this post in threaded view
|

Re: Basic Recode syntax not creating new Variable

Blankdots
OK, I sourced the error. Stupid me.

It seems if you highlight the entire code then click run it works.

Back to the real question. Why doesn't submitting the syntax write a new column with the values in spss file?

spss.Submit(r"""RECODE CAST.1564010_at (Lowest thru 6.8294=1) (6.8295 thru Highest=2) INTO CAST.1564010_at_group.
EXECUTE.""")
Reply | Threaded
Open this post in threaded view
|

Re: Basic Recode syntax not creating new Variable

Jon K Peck
I suggest that you look at the help on working with the syntax window.

I am quite sure that Submit would work with the same syntax, assuming that the data file is open etc (or at least issue an error message.)

So, are you sure that you have actually run the whole program.  If you are doing it from a syntax window, make sure that you have selected the whole program to run.  Watch the status bar.

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




From:        Blankdots <[hidden email]>
To:        [hidden email],
Date:        01/26/2013 08:27 PM
Subject:        Re: [SPSSX-L] Basic Recode syntax not creating new Variable
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




OK, I sourced the error. Stupid me.

It seems if you highlight the entire code then click run it works.

Back to the real question. Why doesn't submitting the syntax write a new
column with the values in spss file?

spss.Submit(r"""RECODE CAST.1564010_at (Lowest thru 6.8294=1) (6.8295 thru
Highest=2) INTO CAST.1564010_at_group.
EXECUTE.""")



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Basic-Recode-syntax-not-creating-new-Variable-tp5717713p5717730.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: Basic Recode syntax not creating new Variable

Blankdots
To reduce factors that may have caused the problem. I reduced the spss sheet to 1 variable named CAST and saved it into a new spss file.

copy pasting the following code (look below) into any new syntax window works and creates a new variables.

RECODE CAST (Lowest thru 6.8294=1) (6.8295 thru Highest=2) INTO CAST_group.
EXECUTE.

I'm still baffled as to why spss.Submit won't rewrite the spss sheet. The submit function obviously has worked because no error message appears. But the variable is not recoded and no new column appears.

from __future__ import with_statement

def main():
    pass

if __name__ == '__main__':
    main()

import spss
import SpssClient
import spssaux

#for getting genenames list from genedata

spss.Submit (r"""GET FILE='E:\Work\Masters\SC177 SPS Work\Basic.Sav'.""")

spss.Submit(r"""
RECODE CAST (Lowest thru 6.8294=1) (6.8295 thru Highest=2) INTO CAST_group.
EXECUTE.""")
Reply | Threaded
Open this post in threaded view
|

Re: Basic Recode syntax not creating new Variable

Richard Ristow
In reply to this post by Blankdots
A side issue. At 09:29 PM 1/26/2013, Blankdots wrote, posting the
code (which I've reformatted):

>RECODE CAST.1564010_at
>    (Lowest thru 6.8294=1)
>    (6.8295 thru Highest=2)
>    INTO CAST.1564010_at_group.

The trouble with this, as discussed in recent thread "Recoding
values" (Wed 23 Jan - Thu 24 Jan), is that it will miss any value
falling between 6.8294 and 6.8295. You may have such values even if
your data was entered as decimal numbers with only four decimal
places, because your inputs will be rounded slightly to fit the
binary number format that SPSS uses.

Preferred is

RECODE  CAST.1564010_at
    (6.8295 thru Highest=2)
    (Lowest thru 6.8295=1)
    INTO CAST.1564010_at_group.

Notice that the ranges now overlap -- 6.8295 is the high bound of one
and the low bound of the other -- so all numbers are captured.

Notice, also, that the order of the RECODE clauses is reversed; the
higher range (6.8295 thru Highest) is now specified first. That
ensures that the break point, 6.8295, is taken as belonging to the
higher range, as you've made clear you want.

By the by -- it looks like your practice is to run SPSS code almost
exclusively through Python. Is there a particular reason for this?
Among other difficulties, it gives you two layers of code to debug
(the Python that generates the SPSS, and the SPSS itself); and it may
be making it harder to get a clear understanding how SPSS 'thinks'.

=====================
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: Basic Recode syntax not creating new Variable

Art Kendall
If you run the syntax I posted in response to this post you will notice that some of the cases do not recode for precisely the reason you mention.
Art Kendall
Social Research Consultants
On 1/28/2013 2:37 PM, Richard Ristow wrote:
A side issue. At 09:29 PM 1/26/2013, Blankdots wrote, posting the
code (which I've reformatted):

RECODE CAST.1564010_at
   (Lowest thru 6.8294=1)
   (6.8295 thru Highest=2)
   INTO CAST.1564010_at_group.

The trouble with this, as discussed in recent thread "Recoding
values" (Wed 23 Jan - Thu 24 Jan), is that it will miss any value
falling between 6.8294 and 6.8295. You may have such values even if
your data was entered as decimal numbers with only four decimal
places, because your inputs will be rounded slightly to fit the
binary number format that SPSS uses.

Preferred is

RECODE  CAST.1564010_at
   (6.8295 thru Highest=2)
   (Lowest thru 6.8295=1)
   INTO CAST.1564010_at_group.

Notice that the ranges now overlap -- 6.8295 is the high bound of one
and the low bound of the other -- so all numbers are captured.

Notice, also, that the order of the RECODE clauses is reversed; the
higher range (6.8295 thru Highest) is now specified first. That
ensures that the break point, 6.8295, is taken as belonging to the
higher range, as you've made clear you want.

By the by -- it looks like your practice is to run SPSS code almost
exclusively through Python. Is there a particular reason for this?
Among other difficulties, it gives you two layers of code to debug
(the Python that generates the SPSS, and the SPSS itself); and it may
be making it harder to get a clear understanding how SPSS 'thinks'.

=====================
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
Art Kendall
Social Research Consultants