Dear list! I have a file with 2 date variables, (indate and outdate) in the date format dd-mmm-yyyy. I want to construct a variable that shows the ICD-revision (7, 8 ,9 or 10) for each outdate. I try the following: if (outdate ge 01-jan-1958 and outdate le 31-dec-1968)icdrev=7. if (outdate ge 01-jan-1969 and outdate le 31-dec-1986)icdrev=8. if (outdate ge 01-jan-1987 and outdate le 31-dec-1996)icdrev=9. if (outdate ge 01-jan-1997)icdrev=10. EXECUTE. This results in: Error # 4285 in column 20. Text: jan Incorrect variable name: either the name is more than 64 characters, or it is not defined by a previous command. Execution of this command stops. I then try with: if (outdate ge 01-01-1958 and outdate le 31-12-1968)icdrev=7. if (outdate ge 01-01-1969 and outdate le 31-12-1986)icdrev=8. if (outdate ge 01-01-1987 and outdate le 31-12-1996)icdrev=9. if (outdate ge 01-01-1997)icdrev=10. EXECUTE. This results in setting all cases to ICDREV=10 although I know for sure that there are other outdates in the file. What is going on here? I probably can’t see the wood because of all the trees. Can anybody help? When it comes to date formats I also wonder why there are no date formats in SPSS of the type: YYYYMMDD (YYMMDD) or YYYY-MM-DD (YY-MM-DD) These are the common date formats in Scandinavia and I am informed also in many Asian countries. If any developers in SPSS are reading this, would it not be a good idea to incorporate these formats? best Staffan Lindberg Sweden |
Staffan, look at the date/time formats in the syntax reference
and then note the number function..
if (outdate
ge number('01-jan-1958',date11) and outdate le number('31-dec-1968',date11))icdrev=7.
etc.
if (outdate ge
01-jan-1969 and outdate le 31-dec-1986)icdrev=8. if (outdate ge
01-jan-1987 and outdate le 31-dec-1996)icdrev=9. if (outdate ge
01-jan-1997)icdrev=10. EXECUTE. But, here's
something else. It looks like all you are interested in is the year.
Thus:
if (xdate.year(outdate) ge number(substr('01-jan-1969',8,4),f4.0) and xdate.year(outdate) le number(substr('31-dec-1986',8,4),f4.0))icdrev=8.
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Staffan Lindberg Sent: Tuesday, September 20, 2011 7:47 AM To: [hidden email] Subject: Computing with date variables. Some perplexities. Dear list! I have a file with 2 date variables, (indate
and outdate) in the date format dd-mmm-yyyy. I want to construct a variable that
shows the ICD-revision (7, 8 ,9 or 10) for each outdate. I try the
following: if (outdate ge 01-jan-1958 and outdate le
31-dec-1968)icdrev=7. if (outdate ge 01-jan-1969 and outdate le
31-dec-1986)icdrev=8. if (outdate ge 01-jan-1987 and outdate le
31-dec-1996)icdrev=9. if (outdate ge
01-jan-1997)icdrev=10. EXECUTE. This results in: Error # 4285 in column 20. Text: jan Incorrect variable name: either the name is more than 64 characters,
or it is not
defined by a previous command. Execution of this command stops. I
then try with: if (outdate ge 01-01-1958 and outdate le
31-12-1968)icdrev=7. if (outdate ge 01-01-1969 and outdate le
31-12-1986)icdrev=8. if (outdate ge 01-01-1987 and outdate le
31-12-1996)icdrev=9. if (outdate ge
01-01-1997)icdrev=10. EXECUTE. This results in setting all cases to
ICDREV=10 although I know for sure that there are other outdates in the file.
What is going on here? I probably can’t see the wood because of all the trees.
Can anybody help? When it comes to date formats I also wonder
why there are no date formats in SPSS of the type: YYYYMMDD (YYMMDD) or YYYY-MM-DD (YY-MM-DD) These are the common date formats in
Scandinavia and I am informed also in many Asian countries. If any developers in
SPSS are reading this, would it not be a good idea to incorporate these
formats? best Staffan Lindberg Sweden |
Administrator
|
In reply to this post by Staffan Lindberg
Here are a couple methods using the RANGE and DATE.DMY functions.
[1] A nested DO-IF: do if range(outdate,date.dmy(1,1,1958),date.dmy(31,12,1968)). - compute icdrev = 7. else if range(outdate,date.dmy(1,1,1969),date.dmy(31,12,1986)). - compute icdrev = 8. else if range(outdate,date.dmy(1,1,1987),date.dmy(31,12,1996)). - compute icdrev = 9. else if outdate GE date.dmy(1,1,1997). - compute icdrev = 10. end if. [2] A DO-REPEAT, which is quite a bit tidier. But notice that it requires you to insert an upper limit on year for the case where icdrev = 10. do repeat #y1 = 1958 1969 1987 1997 / #y2 = 1968 1986 1996 2100 / # = 7 8 9 10 . - if range(outdate,date.dmy(1,1,#y1),date.dmy(31,12,#y2)) icdrev = #. end repeat. HTH.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Administrator
|
In reply to this post by Staffan Lindberg
Cleaner code (which should work -UNTESTED-):
IF RANGE(outdate,DATE.MDY(1,1,1958),DATE.MDY(12,31,1968)) icdrev=7. IF RANGE(outdate,DATE.MDY(1,1,1969),DATE.MDY(12,31,1986)) icdrev=8. IF RANGE(outdate,DATE.MDY(1,1,1987),DATE.MDY(12,31,1996)) icdrev=9. IF RANGE(outdate,DATE.MDY(1,1,1997),DATE.MDY(12,31,2020)) icdrev=10. *OR* COMPUTE icdrev=XDATE.YEAR(outdate). RECODE icdrev (1958 THRU 1968=7) (1969 THRU 1986=8) (1987 THRU 1996=9) (1997 THRU HI=10) "if (outdate ge 01-01-1958 and outdate le 31-12-1968)icdrev=7. if (outdate ge 01-01-1969 and outdate le 31-12-1986)icdrev=8. if (outdate ge 01-01-1987 and outdate le 31-12-1996)icdrev=9. if (outdate ge 01-01-1997)icdrev=10." **EXECUTE.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Administrator
|
That RECODE method is neat, David. You'll want to add a command terminator though. ;-)
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
In reply to this post by Bruce Weaver
Regarding date formats, Statistics does
have yyyy/mm/dd and yy/mm/dd formats - see SDATE. In understanding
these formats, note that wherever internal delimiters are allows, you can
use a dash, period, comma, or slash.
It is difficult to add new date formats for variables, because that would break compatibility of the sav file with older versions of Statistics. (There are actually 39 variable formats supported altogether). However, other formats can be read or produced using functions in the extendedTransforms.py programmability module available from the SPSS Community site. Regards, Jon Peck (no "h") Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 [snip] > > When it comes to date formats I also wonder why there are no date formats > in > SPSS of the type: > > > > YYYYMMDD (YYMMDD) or > > YYYY-MM-DD (YY-MM-DD) > > > > These are the common date formats in Scandinavia and I am informed also in > many Asian countries. If any developers in SPSS are reading this, would it > not be a good idea to incorporate these formats? > > > > best > > > > Staffan Lindberg > > Sweden > |
Administrator
|
In reply to this post by Staffan Lindberg
FWIW:
Shedding light on the 'trees'. Your original syntax was treating the - as subtraction rather than a date delimiter. In effect you were comparing dates (huge numbers) to negative numbers ;-) HTH, David
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Jon K Peck
At 11:13 AM 9/20/2011, Jon K Peck wrote:
>It is difficult to add new date formats for variables, because that >would break compatibility of the sav file with older versions of Statistics. It surprises me that you say that. I'd have thought adding formats wouldn't affect the older files at all -- after all, the formats named in the older data dictionaries would still be fully supported. ===================== 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 |
Administrator
|
Hi Richard,
I believe Jon's indicating that older versions would be unable to read the new data files. David On Thu, Sep 29, 2011 at 5:01 PM, Richard Ristow [via SPSSX Discussion] <[hidden email]> wrote: > At 11:13 AM 9/20/2011, Jon K Peck wrote: > >>It is difficult to add new date formats for variables, because that >>would break compatibility of the sav file with older versions of >> Statistics. > > It surprises me that you say that. I'd have thought adding formats > wouldn't affect the older files at all -- after all, the formats > named in the older data dictionaries would still be fully supported. > > ===================== > 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 > > > ________________________________ > If you reply to this email, your message will be added to the discussion > below: > http://spssx-discussion.1045642.n5.nabble.com/Computing-with-date-variables-Some-perplexities-tp4822256p4854667.html > To unsubscribe from Computing with date variables. Some perplexities., click > here.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Richard Ristow
Well no. What would an older version
do when confronted with a newer sav file containing a format that it didn't
anticipate and doesn't understand? Crash, maybe?
Jon Peck (no "h") Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: Richard Ristow <[hidden email]> To: Jon K Peck/Chicago/IBM@IBMUS, [hidden email] Date: 09/29/2011 02:52 PM Subject: Re: Computing with date variables. Some perplexities. At 11:13 AM 9/20/2011, Jon K Peck wrote: >It is difficult to add new date formats for variables, because that >would break compatibility of the sav file with older versions of Statistics. It surprises me that you say that. I'd have thought adding formats wouldn't affect the older files at all -- after all, the formats named in the older data dictionaries would still be fully supported. |
Administrator
|
In reply to this post by Richard Ristow
When I think about it, I wonder if an unrecognized FORMAT would cause
older versions to scream and die or whether it would fail gracefully and simply return default numeric format to the data values (user would then need to apply a supported date format and off they go ? On Thu, Sep 29, 2011 at 5:32 PM, David Marso <[hidden email]> wrote: > Hi Richard, > I believe Jon's indicating that older versions would be unable to read > the new data files. > David > On Thu, Sep 29, 2011 at 5:01 PM, Richard Ristow [via SPSSX Discussion] > <[hidden email]> wrote: >> At 11:13 AM 9/20/2011, Jon K Peck wrote: >> >>>It is difficult to add new date formats for variables, because that >>>would break compatibility of the sav file with older versions of >>> Statistics. >> >> It surprises me that you say that. I'd have thought adding formats >> wouldn't affect the older files at all -- after all, the formats >> named in the older data dictionaries would still be fully supported. >> >> ===================== >> 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 >> >> >> ________________________________ >> If you reply to this email, your message will be added to the discussion >> below: >> http://spssx-discussion.1045642.n5.nabble.com/Computing-with-date-variables-Some-perplexities-tp4822256p4854667.html >> To unsubscribe from Computing with date variables. Some perplexities., click >> here. >
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Free forum by Nabble | Edit this page |