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

Extracting Week from Date Variable

617 views
Skip to first unread message

Valli

unread,
Feb 25, 2011, 7:54:45 AM2/25/11
to
Hi Everyone,

I need some help in extracting week from date variable in SPSS.

I have one variables (datex) which contains the some date values, i
try to extract the week of that date variable (datex) using
xdate.week(datex). I tried the same in excel using the weeknum
function. Below i provided the results from both excel and spss. How
to get similar results as excel in spss?

Datex Excel Result SPSS Result
1/1/2010 1 1
1/2/2010 1 1
1/3/2010 2 1
1/4/2010 2 1
1/5/2010 2 1
1/6/2010 2 1
1/7/2010 2 1
1/8/2010 2 2
1/9/2010 2 2
1/10/2010 3 2
1/11/2010 3 2
1/12/2010 3 2
1/13/2010 3 2
1/14/2010 3 2
1/15/2010 3 3

Thanks for your help.

Regards,
Valli

Jon Peck

unread,
Feb 25, 2011, 9:31:22 AM2/25/11
to
SPSS and Excel use different rules in calculating the week number. In SPSS, the week number is calculated starting from Jan 1; in Excel, the first week is the week containing January 1, but the next Sunday starts week 2.

To get the equivalent result in SPSS, you need to adjust the date input to xdate.week according to the day number.

* plain week number.
compute week = xdate.week(datex).
* day of week.
compute wkday = xdate.wkday(datex).
* day of week for first day of year.
compute startwkday = xdate.wkday(date.yrday(xdate.year(datex),1)).
* adjusted week number.
compute newweek = xdate.week(datex + (startwkday-1)*86400).

HTH,
Jon Peck

0 new messages