user3653772
user3653772

Reputation: 13

Calculating who is about to turn 3 years of age in SPSS

I would like to determine who is about to turn 3 years of age in SPSS code. How can this best be done? The two ways I crafted were:

1.

compute Almost3Age = ((xdate.tday($time) - xdate.tday(dobmtu))/365.25).

compute Almost3 = 0.
if Almost3Age ge 2.91 and Almost3Age lt 3 Almost3 = 1.

********************OR******************************* 2.

compute Almost3 = 0.
if (xdate.year($time) - xdate.year(dobmtu) eq 3) and (xdate.month($time) = xdate.month(dobmtu)
   and xdate.mday($time) lt xdate.mday(dobmtu)) Almost3 = 1.

Any thoughts?

Upvotes: 1

Views: 77

Answers (1)

Chet Meinzer
Chet Meinzer

Reputation: 1741

Only problem with your code is that it does not take into account different length months.

I need to know who is 2 years and 11 months old.
I don't want to cut out anyone that will turn 3 exactly a month from today, so i'll take today's date, subtract a day, and calculate 2yrs and 11 months variable.

if you don't want to include people turning 3 today...

compute twoyears11months=datedif(datesum($time,-1,'days'),dobmtu,'months').
select if twoyears11months =35.

otherwise, exclude bday today and in one line.

select if datedif($time,dobmtu,'months') =35.

Upvotes: 1

Related Questions