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
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