|
Dear members
I would grateful if any could help me with a solution to this problem. I have 2 date variables event reported date new date 08-JAN-2007 . 12-jan-2007 14-JAN-2007 16-JAN-2007 For the rows where the value is missing in variable 1, I am trying to replace them with dates from the second variable that is 'new date'. I have checked the date format for both variables and they are identical. I have tried the following syntax and it seems to be working but unfortunately I do not get the results in the data file. Does the recode command work only for numeric and string variables? RECODE EventReportedDate (SYSMIS). EXECUTE . IF (EventReportedDate=$SYSMIS) eventreporteddate = newdate . EXECUTE. thanks regards Thara Vardhan Senior Statistician Planning & Results Organisation Review and Support NSW Police Tel: (02) 8835-8526 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ This message and any attachment is confidential and may be privileged or otherwise protected from disclosure. If you have received it by mistake, please let us know by reply and then delete it from your system; you should not copy the message or disclose its contents to anyone. ===================== 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 |
|
At 06:38 PM 2/21/2008, Thara Vardhan wrote:
>I have 2 date variables |-----------------------------|---------------------------| |Output Created |21-FEB-2008 19:27:37 | |-----------------------------|---------------------------| EventReportedDate NewDate 08-JAN-2007 . . 12-JAN-2007 14-JAN-2007 . 16-JAN-2007 . Number of cases read: 4 Number of cases listed: 4 >For the rows where the value is missing in variable 1, I am trying >to replace them with dates from the second variable that is 'new date'. > >I have tried the following syntax and it seems to be working but >unfortunately I do not get the results in the data file. Apart from the EXECUTE commands (which slow the processing, and do nothing useful), you have >RECODE > EventReportedDate (SYSMIS). > >Does the recode command work only for numeric and string variables? RECODE works for all variables, though it can be awkward for dates. But, this one isn't valid: RECODE EventReportedDate (SYSMIS). >Error # 4651 in column 29. Text: ) >The symbol ')' was used on the RECODE command incorrectly. This >symbol must follow either the replacement value on the right of the >equals sign or the keyword CONVERT. >This command not executed. What were you trying to accomplish here? Then, here's the real problem: >IF (EventReportedDate=$SYSMIS) eventreporteddate = newdate . See many on-list discussions of missing values in comparisons. Without going into it all, the test "(EventReportedDate=$SYSMIS)" is *never* 'TRUE'. Here's the correct form: IF (SYSMIS(EventReportedDate)) eventreporteddate = newdate . LIST. List |-----------------------------|---------------------------| |Output Created |21-FEB-2008 19:42:10 | |-----------------------------|---------------------------| EventReportedDate NewDate 08-JAN-2007 . 12-JAN-2007 12-JAN-2007 14-JAN-2007 . 16-JAN-2007 . Number of cases read: 4 Number of cases listed: 4 By the way, >I have checked the date format for both variables and they are identical. That has nothing to do with it, one way or the other. Date values can be compared with each other, and copied to each other, regardless of what format they have - as long as it is an SPSS date format. ============================= APPENDIX: Test data, and code ============================= (Test data gives the correct result, but with warning messages) DATA LIST LIST / EventReportedDate NewDate (DATE11 DATE11). BEGIN DATA 08-JAN-2007 . 12-jan-2007 14-JAN-2007 16-JAN-2007 END DATA. LIST. RECODE EventReportedDate (SYSMIS). LIST. IF (SYSMIS(EventReportedDate)) eventreporteddate = newdate . LIST. ===================== 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 |
|
Hi Richard
Thank you so much for your prompt reply and help.Initially by using recoding I was trying to define records with a . as missing values. Unfortunately although the correct syntax you have sent me is working but it is not showing the results in the data file. I am perplexed and I don't understand what is going on.I am using version SPSS15.0. IF (SYSMIS(EventReportedDate)) eventreporteddate = newdate. exe. EventReportedDate NewDate 08-JAN-2007 . . 12-JAN-2007 14-JAN-2007 . 16-JAN-2007 . All I was trying to accomplish was an end result in event reported date as event reported date 08-JAN-2007 12-JAN-2007 14-JAN-2007 16-JAN-2007 thanks regards Thara Vardhan Senior Statistician Planning & Results Organisation Review and Support NSW Police Tel: (02) 8835-8526 Richard Ristow <[hidden email]> 22/02/2008 11:46 To Thara Vardhan <[hidden email]>, [hidden email] cc Subject Re: seeking help with date variables At 06:38 PM 2/21/2008, Thara Vardhan wrote: >I have 2 date variables |-----------------------------|---------------------------| |Output Created |21-FEB-2008 19:27:37 | |-----------------------------|---------------------------| EventReportedDate NewDate 08-JAN-2007 . . 12-JAN-2007 14-JAN-2007 . 16-JAN-2007 . Number of cases read: 4 Number of cases listed: 4 >For the rows where the value is missing in variable 1, I am trying >to replace them with dates from the second variable that is 'new date'. > >I have tried the following syntax and it seems to be working but >unfortunately I do not get the results in the data file. Apart from the EXECUTE commands (which slow the processing, and do nothing useful), you have >RECODE > EventReportedDate (SYSMIS). > >Does the recode command work only for numeric and string variables? RECODE works for all variables, though it can be awkward for dates. But, this one isn't valid: RECODE EventReportedDate (SYSMIS). >Error # 4651 in column 29. Text: ) >The symbol ')' was used on the RECODE command incorrectly. This >symbol must follow either the replacement value on the right of the >equals sign or the keyword CONVERT. >This command not executed. What were you trying to accomplish here? Then, here's the real problem: >IF (EventReportedDate=$SYSMIS) eventreporteddate = newdate . See many on-list discussions of missing values in comparisons. Without going into it all, the test "(EventReportedDate=$SYSMIS)" is *never* 'TRUE'. Here's the correct form: IF (SYSMIS(EventReportedDate)) eventreporteddate = newdate . LIST. List |-----------------------------|---------------------------| |Output Created |21-FEB-2008 19:42:10 | |-----------------------------|---------------------------| EventReportedDate NewDate 08-JAN-2007 . 12-JAN-2007 12-JAN-2007 14-JAN-2007 . 16-JAN-2007 . Number of cases read: 4 Number of cases listed: 4 By the way, >I have checked the date format for both variables and they are identical. That has nothing to do with it, one way or the other. Date values can be compared with each other, and copied to each other, regardless of what format they have - as long as it is an SPSS date format. ============================= APPENDIX: Test data, and code ============================= (Test data gives the correct result, but with warning messages) DATA LIST LIST / EventReportedDate NewDate (DATE11 DATE11). BEGIN DATA 08-JAN-2007 . 12-jan-2007 14-JAN-2007 16-JAN-2007 END DATA. LIST. RECODE EventReportedDate (SYSMIS). LIST. IF (SYSMIS(EventReportedDate)) eventreporteddate = newdate . LIST. All mail is subject to content scanning for possible violation of New South Wales Police Force Electronic Messaging Policy. All NSWPF employees are required to familiarise themselves with the content of the policy, found under Policies on the NSW Police Force Intranet. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ This message and any attachment is confidential and may be privileged or otherwise protected from disclosure. If you have received it by mistake, please let us know by reply and then delete it from your system; you should not copy the message or disclose its contents to anyone. ===================== 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 Richard Ristow
As Richard says,
RECODE works for all variables, though it can be awkward for dates. However, one of our Python supplementary modules handles date notation for recodes. It also creates value labels for the recoded variable automatically. Here is an example. The code below recodes the date variable bdate (in employee data.sav) into bdaterecode. It takes a dictionary of values to recode. So, for example, the date 1952-02-03 is recoded into the value 100. The generate line executes the commands, but it also returns the syntax for the Recode and for generating value labels for the recoded data in case that is wanted for other reasons. begin program. import spss, specialtransforms rec = specialtransforms.Recode("bdaterecode", "bdate", {'1952-02-03': 100, '1958-05-23':200}, inputtype='D', elserc=300) syntax = rec.generate(execute=True) print syntax end program. The syntax printed would be NUMERIC bdaterecode (F8.0). RECODE bdate (11654150400=100) (11852956800=200) (ELSE=300) INTO bdaterecode. VALUE LABELS bdaterecode 200 "1958-05-23" 100 "1952-02-03". This requires at least SPSS 14.0.1, the Python plugin, and the specialtransforms module, the latter two from SPSS Developer Central (www.spss.com/devcentral). Regards, Jon Peck ===================== 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 thara vardhan-2
At 08:21 PM 2/21/2008, Thara Vardhan wrote:
>Thank you so much for your prompt reply and help. All I was trying >to accomplish was an end result in event reported date as > >event reported date > >08-JAN-2007 >12-JAN-2007 >14-JAN-2007 >16-JAN-2007 > >Unfortunately although the correct syntax you have sent me is >working but it is not showing the results in the data file. I am >perplexed and I don't understand what is going on.I am using version SPSS15.0. > >IF (SYSMIS(EventReportedDate)) eventreporteddate = newdate. >exe. > >EventReportedDate NewDate > > 08-JAN-2007 . > . 12-JAN-2007 > 14-JAN-2007 . > 16-JAN-2007 . I truly don't see it. Here's the exact syntax I posted before, including your test data, but dropping the erroneous RECODE: .............................. (Test data gives the correct result, but with warning messages) DATA LIST LIST / EventReportedDate NewDate (DATE11 DATE11). BEGIN DATA 08-JAN-2007 . 12-jan-2007 14-JAN-2007 16-JAN-2007 END DATA. LIST. RECODE EventReportedDate (SYSMIS). LIST. IF (SYSMIS(EventReportedDate)) eventreporteddate = newdate . LIST. .............................. It worked for me; see the output, in my previous posting. Run it to draft output, and post what you get, if it doesn't work. But I don't see why what you did shouldn't work. Maybe, run *that* to draft output, too. But not just the single statement; all the code from the GET FILE, or whatever loads the file, up to the point where you don't seem to have the right result. ===================== 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 Peck, Jon
At 09:13 PM 2/21/2008, Peck, Jon wrote:
>However, one of our Python supplementary modules handles date >notation for recodes. It also creates value labels for the recoded >variable automatically. Here is an example. The code below recodes >the date variable bdate (in employee data.sav) into bdaterecode. It >takes a dictionary of values to recode. So, for example, the date >1952-02-03 is recoded into the value 100. > >The generate line executes the commands, but it also returns the >syntax for the Recode and for generating value labels for the >recoded data in case that is wanted for other reasons. > >begin program. >import spss, specialtransforms > >rec = specialtransforms.Recode("bdaterecode", "bdate", > {'1952-02-03': 100, '1958-05-23':200}, inputtype='D', elserc=300) >syntax = rec.generate(execute=True) >print syntax >end program. > >The syntax printed would be >NUMERIC bdaterecode (F8.0). >RECODE bdate (11654150400=100) (11852956800=200) (ELSE=300) INTO bdaterecode. >VALUE LABELS bdaterecode 200 "1958-05-23" 100 "1952-02-03". Good stuff. But for clarity, would you be willing to have the emitted syntax look something like RECODE bdate (11654150400 /* 1952-02-03 */ =100) (11852956800 /* 1958-05-23 */ =200) (ELSE =300) INTO bdaterecode. ===================== 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 |
|
Hi Richard,
I could add the inline comments you suggest to the generated RECODE syntax, but I didn't do that because the generated VALUE LABELS syntax right afterwards seems to show the mapping pretty clearly. I thought that especially with more complex recodes such as the example following it would be clearer without interspersed comments. In this example, a range of dates is mapped, and two distinct input values are mapped to the same output. begin program. import spss, specialtransforms rec = specialtransforms.Recode("bdaterecode", "bdate", {'1952-02-03': 100, '1958-05-23':200, ('1960-01-01', '1970-12-31'):400, '1940-01-23':200}, inputtype='D', elserc=300) syntax = rec.generate(execute=True) print syntax[1] print syntax[2] end program. The generated syntax in this case looks like this. RECODE bdate (11654150400=100) (11852956800=200) (11274508800=200) (11903760000 THRU 12250828800=400) (ELSE=300) INTO bdaterecode. VALUE LABELS bdaterecode 200 "1958-05-23, 1940-01-23" 400 "(1960-01-01 - 1970-12-31)" 100 "1952-02-03". The VALUE LABELS syntax has the advantage of grouping together all the input values that map to the same output value. Are you still convinced that interspersed comments are a good idea? By the way, since this function works with any kind of input data, the comments would sometimes just repeat the numeric or string value already stated in the syntax unless they were restricted to date input. -Jon -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Richard Ristow Sent: Friday, February 22, 2008 9:14 PM To: [hidden email] Subject: Re: [SPSSX-L] seeking help with date variables At 09:13 PM 2/21/2008, Peck, Jon wrote: >However, one of our Python supplementary modules handles date >notation for recodes. It also creates value labels for the recoded >variable automatically. Here is an example. The code below recodes >the date variable bdate (in employee data.sav) into bdaterecode. It >takes a dictionary of values to recode. So, for example, the date >1952-02-03 is recoded into the value 100. > >The generate line executes the commands, but it also returns the >syntax for the Recode and for generating value labels for the >recoded data in case that is wanted for other reasons. > >begin program. >import spss, specialtransforms > >rec = specialtransforms.Recode("bdaterecode", "bdate", > {'1952-02-03': 100, '1958-05-23':200}, inputtype='D', elserc=300) >syntax = rec.generate(execute=True) >print syntax >end program. > >The syntax printed would be >NUMERIC bdaterecode (F8.0). >RECODE bdate (11654150400=100) (11852956800=200) (ELSE=300) INTO bdaterecode. >VALUE LABELS bdaterecode 200 "1958-05-23" 100 "1952-02-03". Good stuff. But for clarity, would you be willing to have the emitted syntax look something like RECODE bdate (11654150400 /* 1952-02-03 */ =100) (11852956800 /* 1958-05-23 */ =200) (ELSE =300) INTO bdaterecode. ===================== 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 |
| Free forum by Nabble | Edit this page |
