I'm having trouble filtering and deleting by dates in SPSS 12.0 I need
to filter/delete about two years worth of data in a five or six year
file. I've used the following to try to filter all data before 7/9/02,
but it does not work correctly. It filters out 4/5/2001, but not
10/25/2001.
USE ALL.
COMPUTE filter_$=(XDATE.YEAR(TEST_DATE) < 2003 & XDATE.MONTH(TEST_DATE)
< 8 & XDATE.MDAY(TEST_DATE) < 10).
VARIABLE LABEL filter_$ 'XDATE.YEAR(TEST_DATE) < 2003 &
XDATE.MONTH(TEST_DATE) < 8 & XDATE.MDAY(TEST_DATE) < 10'+
' (FILTER)'.
VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'.
FORMAT filter_$ (f1.0).
FILTER BY filter_$.
EXECUTE .
I know it has to be something small that I'm missing. Can anyone help?
Thanx in advance,
vf
I have SPSS 14, but I still think you should be able to define a
temporary work date column for 7/9/02 and then just compare it with the
column of interest. If you can get the format right for a date
literal, you might be able to do it directly against that literal,
perhaps with the function DATE.MDY. I believe dates are held
internally in SPSS in ISO format or a convertible equivalent, i.e.
YYYYMMDD etc.
Some testing on a small volume of data would be advisable.
Robert
Use all.
Select if TEST_DATE >= date.DMYR(07,09,2002).
Exe.
HtH
Mike
I think the other reason why it wasn't working before is that your code
looked to see if month was < 8, day was < 10 and year was <2003. All
independently - so 10/25/2001 was fail (month) fail (day) and pass (year) -
overall it doesn't pick it up.
Programming it ugly would have had one clause for 2003+ (pass), one for
2002 - check month (<8 (fail), =8, check day, and >8 (pass)), and one for
2001- (fail). All in all, a lot more complex than your syntax.
Richard.
DEFINE SelectRangeDatas (!POSITIONAL !TOKENS(1)/ !POSITIONAL
!CHAREND('/')/ !POSITIONAL !CHAREND('/')/ !POSITIONAL !CHAREND('a')/
!POSITIONAL !CHAREND('/')/ !POSITIONAL !CHAREND('/')/ !POSITIONAL
!CMDEND)
COMPUTE RANGE_DATAS =
RANGE(!1,DATE.DMY(!CONCAT(!2,',',!3,',',!4)),DATE.DMY(!CONCAT(!5,',',!6,',',!7)))
.
EXECUTE .
FILTER OFF.
USE ALL.
SELECT IF(NOT(RANGE_DATAS =0)).
EXECUTE .
DELETE VARIABLES RANGE_DATAS.
!ENDDEFINE.
/*SelectRangeDatas Data 01/01/2006 a 01/01/2006.
Thanks
Carlos Renato
Statistician
vinfurnier escreveu: