Can anyone offer some syntax for recoding date ranges.
For example.
11-Dec-2005 to 31-Oct-2008=1
01-Nov-2008 to 04-Nov-2008=2
If date is blank (or SYSMIS)=3
I realize that it is possible to use the numeric date value, however,
I find this to be somwhat cumbersome.
Any suggestions would be helpful.
Txs
Damir
The Recode command only accepts the numeric value of date variables.
There are two things that can help.
First, if you are creating cutpoints for a date variable, use the
Visual Binner (Transform>Visual Binner). It shows you the
distribution and allows you to enter cutpoints in the date format of
the variable in question. It paste the numerical values when
generating syntax.
Second, there is a programmability module, specialtransforms.py,
downloadable from SPSS Developer Central, www.spss.com/devcentral,
that generates recodes accepting date literals.
Here is an example from the docstring for the Recode function in that
module.
For a date variable,
rec = specialtransforms.Recode("bdaterecode", "bdate",
{'1952-02-03': 100, '1958-05-23':200}, inputtype='D',
elserc=300)
syntax = rec.generate(execute=True)
This function can also generate value labels for the recoded variable
based on the recode definition. This works for date variable and
other formats, too.
This module can be used with any version of SPSS that supports
programmability (14+). It requires the Python Plug-In from Developer
Central.
HTH,
Jon Peck
Do if date1>=date.dmy(11,12,2005) and date1<= date.dmy(31,10,2008).
comp daterec=1.
Else if date1>=date.dmy(1,11,2008) and date1<= date.dmy(4,11,2008).
comp daterec=2.
end if.
if sysmis(date1) daterec=3.
exe.
> Jon Peck- Hide quoted text -
>
> - Show quoted text -
Old fashioned? Who's showing their age now, Fred? ;-) It will
probably come as no surprise to you that I prefer this method to Jon's
Python code. It has the huge advantage of being understandable by the
typical user.
--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."