Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Filtering or deleting by date

1,345 views
Skip to first unread message

vinfurnier

unread,
Nov 27, 2006, 9:45:19 AM11/27/06
to
Hi -

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

Robert Jones

unread,
Nov 27, 2006, 11:09:26 AM11/27/06
to

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

michael....@tangozebra.com

unread,
Nov 27, 2006, 11:57:47 AM11/27/06
to
In the select statement you must explicitly define it as a date ie,
(this will delete all files not selected)

Use all.
Select if TEST_DATE >= date.DMYR(07,09,2002).
Exe.

HtH

Mike

vinfurnier

unread,
Nov 27, 2006, 12:39:00 PM11/27/06
to
THANX Mike!!!
That totally helps,
vf

Richard Edlin

unread,
Nov 27, 2006, 5:06:17 PM11/27/06
to

"vinfurnier" <vinfu...@yahoo.com> wrote in message
news:1164649139.9...@14g2000cws.googlegroups.com...

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.


Statistician_Brazil

unread,
Nov 29, 2006, 7:29:18 AM11/29/06
to
Dear friend...use this Macro for solve your problem.

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:

0 new messages