Dear listers,
Can anyone find a way to get this problem with to work? The problem (basically this is the last line of code, that is, the IF statement) needs to work with the global settings I have defined. I would be very appreciative if anyone could help. DATA LIST FIXED /activdat 1-10 (EDATE) episode_year 12-15 (F) . BEGIN DATA 01.07.2005 01.08.2005 01.07.2005 01.07.2005 2003 30.06.2006 30.06.2006 END DATA. ***Global settings***. define !extract_yr_dmy_st ( ) DATE.DMY(01,07,2005) !enddefine. define !extract_yr_dmy_st2 ( ) DATE.DMY(31,06,2006) !enddefine. define !extract_year ( ) '2006' !enddefine. ***End Global settings***. IF ((episode_year=' ') AND (activdat >=!extract_yr_dmy_st AND activdat <= !extract_yr_dmy_st2 )) episode_year = number('!extract_year',f4.0). KR, Jonathon Jonathon Little Senior Research Analyst Statewide Mental Health Governance & Performance Mental Health Division Department of Health W.A. 2nd Floor C-Block, 189 Royal Street, East Perth, WA 6004 Tel:08 9222 4089 Fax: 08 9222 2351 e-mail:[hidden email] Visit our website at : www.mental.health.wa.gov.au <http://www.mental.health.wa.gov.au/> The contents of this e-mail transmission are confidential and may be protected by professional privilege. The contents are intended only for the named recipients of the e-mail. If you are not the intended recipient, you are hereby notified that any use, reproduction, disclosure or distribution of the information contained in this e-mail is prohibited. Please notify the sender immediately. |
Hi Jonathon
In your data list, episode_year is defined as an integer, but in your IF statement, you treat it as if it were a string by testing for a value that is specified the way string values are - by enclosing it in single quotes. If what you want to do is test for is a user-missing or system-missing value on episode_year, you can use the MISSING() function - if (missing(episode_year) and ..... Regards Adrian -- Adrian Barnett Research & Information Officer Ph: +61 8 82266615 Research, Analysis and Evaluation Fax: +61 8 82267088 Strategic Planning and Research Branch Strategic Planning and Population Health Division SA Department of Health This e-mail may contain confidential information, which also may be legally privileged. Only the intended recipient(s) may access, use, distribute or copy this e-mail. If this e-mail is received in error, please inform the sender by return e-mail and delete the original. If there are doubts about the validity of this message, please contact the sender by telephone. It is the recipient's responsibility to check the e-mail and any attached files for viruses. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Little, Jonathon Sent: Tuesday, 19 September 2006 3:53 To: [hidden email] Subject: Arithmetic with dates and macros Dear listers, Can anyone find a way to get this problem with to work? The problem (basically this is the last line of code, that is, the IF statement) needs to work with the global settings I have defined. I would be very appreciative if anyone could help. DATA LIST FIXED /activdat 1-10 (EDATE) episode_year 12-15 (F) . BEGIN DATA 01.07.2005 01.08.2005 01.07.2005 01.07.2005 2003 30.06.2006 30.06.2006 END DATA. ***Global settings***. define !extract_yr_dmy_st ( ) DATE.DMY(01,07,2005) !enddefine. define !extract_yr_dmy_st2 ( ) DATE.DMY(31,06,2006) !enddefine. define !extract_year ( ) '2006' !enddefine. ***End Global settings***. IF ((episode_year=' ') AND (activdat >=!extract_yr_dmy_st AND activdat <= !extract_yr_dmy_st2 )) episode_year = number('!extract_year',f4.0). KR, Jonathon Jonathon Little Senior Research Analyst Statewide Mental Health Governance & Performance Mental Health Division Department of Health W.A. 2nd Floor C-Block, 189 Royal Street, East Perth, WA 6004 Tel:08 9222 4089 Fax: 08 9222 2351 e-mail:[hidden email] Visit our website at : www.mental.health.wa.gov.au <http://www.mental.health.wa.gov.au/> The contents of this e-mail transmission are confidential and may be protected by professional privilege. The contents are intended only for the named recipients of the e-mail. If you are not the intended recipient, you are hereby notified that any use, reproduction, disclosure or distribution of the information contained in this e-mail is prohibited. Please notify the sender immediately. |
In reply to this post by Little, Jonathon
At 02:23 AM 9/19/2006, Little, Jonathon wrote:
>The last line of code, that is, the IF statement) needs to work with >the global settings I have defined. >DATA LIST FIXED /activdat 1-10 (EDATE) episode_year 12-15 (F) . [... Test data appreciated, but omitted here ...] >***Global settings***. >define !extract_yr_dmy_st ( ) DATE.DMY(01,07,2005) !enddefine. >define !extract_yr_dmy_st2 ( ) DATE.DMY(31,06,2006) !enddefine. >define !extract_year ( ) '2006' !enddefine. >***End Global settings***. * IF statement, reformatted for reading: . IF ((episode_year=' ') AND (activdat >=!extract_yr_dmy_st AND activdat <= !extract_yr_dmy_st2 )) episode_year = number('!extract_year',f4.0). 1. "(episode_year=' ')" doesn't work. Variable "episode_year" is numeric (F4) and can't be compared with a character string. You mean "SYSMIS(episode_year)". 2. "number('!extract_year',f4.0)" doesn't work. The macro is not expanded within the quotes, so it expands to "episode_year = number('!extract_year',f4.0)"; and, of course, !extract_year isn't a valid numeric string. Probably simplest is to -a. Make !extract_year expand into textual representation of a number: "2006" instead of "'2006'": define !extract_year ( ) 2006 !enddefine. -b. Don't fiddle with the "number" function. Instead of "episode_year = number('!extract_year',f4.0)" use "episode_year = !extract_year." Is this what you wanted? Tested; SPSS draft output: List |-----------------------------|---------------------------| |Output Created |19-SEP-2006 09:05:27 | |-----------------------------|---------------------------| activdat episode_year 01.07.2005 . 01.08.2005 . 01.07.2005 . 01.07.2005 2003 30.06.2006 . 30.06.2006 . Number of cases read: 6 Number of cases listed: 6 ***Global settings***. define !extract_yr_dmy_st ( ) DATE.DMY(01,07,2005) !enddefine. define !extract_yr_dmy_st2 ( ) DATE.DMY(31,06,2006) !enddefine. define !extract_year ( ) 2006 !enddefine. ***End Global settings***. PRESERVE. SET MPRINT ON. * IF statement, reformatted for reading: . 92 M> * IF statement, reformatted for reading: . 93 M> IF ( SYSMIS(episode_year) AND 94 M> IF ( SYSMIS(episode_year) AND (activdat >=!extract_yr_dmy_st AND 95 M> (activdat >=DATE.DMY(01,07,2005) 96 M> AND activdat <= !extract_yr_dmy_st2 )) 97 M> activdat <= DATE.DMY(31,06,2006) 98 M> )) episode_year = !extract_year. 99 M> episode_year = 2006 100 M> . RESTORE. 101 M> RESTORE. LIST. List |-----------------------------|---------------------------| |Output Created |19-SEP-2006 09:05:27 | |-----------------------------|---------------------------| activdat episode_year 01.07.2005 2006 01.08.2005 2006 01.07.2005 2006 01.07.2005 2003 30.06.2006 2006 30.06.2006 2006 Number of cases read: 6 Number of cases listed: 6 |
Free forum by Nabble | Edit this page |