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

SPSS Recode date into weekdays

3,072 views
Skip to first unread message

cuix...@gmail.com

unread,
Oct 20, 2013, 3:13:14 AM10/20/13
to
Hi

I have a question about how to recode dates into monday to sunday, i want to achieve it using loop commend, but quite confuse on how to achieve that.

data may like this

1/8/2011
.
.
.
2/8/2011
.
.
3/8/2011
.
.
.
.
.

how can i compute a new variable as 1(Monday) 2(Tuesday)....7(Monday)?

Thanks

Art Kendall

unread,
Oct 20, 2013, 7:57:22 AM10/20/13
to
Open a new instance of SPSS.
Copy and paste the syntax below into a syntax window.
Run it.

data list list/mydate(adate10).
begin data
1/1/2013
1/2/2013
1/3/2013
1/1/2014
1/1/2015
end data.
numeric DayOfWeek(f1).
compute DayOfWeek = xdate.wkday(mydate).
value labels DayOfWeek
1 'Sunday'
2 'Monday'
3 'Tuesday'
4 'Wednesday'
5 'Thursday'
6 'Friday'
7 'Saturday'.
list.

Art Kendall
Social Research Consultants

oceanpi...@gmail.com

unread,
Jan 14, 2015, 12:42:41 PM1/14/15
to
create a dummy variable for day of week in SPSS
COMPUTE wkday=XDATE.WKDAY(date).
execute.
compute Mon=0.
compute Tue=0.
compute Wed=0.
compute Thu=0.
compute Fri=0.
compute Sat=0.
compute Sun=0.
if wkday =1 Sun=1.
if wkday =2 Mon=1.
if wkday =3 Tue=1.
if wkday =4 Wed=1.
if wkday =5 Thu=1.
if wkday =6 Fri=1.
if wkday =7 Sat=1.
execute.

Bruce Weaver

unread,
Jan 14, 2015, 3:40:08 PM1/14/15
to
Note that the OP asked for "1(Monday) 2(Tuesday)", etc. A slight
modification to Art's code will achieve that. E.g.,

data list list/mydate(adate10).
begin data
1/12/2015
1/13/2015
1/14/2015
1/15/2015
1/16/2015
1/17/2015
1/18/2015
1/19/2015
end data.
numeric DayOfWeek(f1).
***************************************** .
compute DayOfWeek = xdate.wkday(mydate)-1.
recode DayOfWeek (0 = 7).
***************************************** .
value labels DayOfWeek
1 'Monday'
2 'Tuesday'
3 'Wednesday'
4 'Thursday'
5 'Friday'
6 'Saturday'
7 'Sunday'.
list.

OUTPUT:
mydate DayOfWeek

01/12/2015 1
01/13/2015 2
01/14/2015 3
01/15/2015 4
01/16/2015 5
01/17/2015 6
01/18/2015 7
01/19/2015 1

Number of cases read: 8 Number of cases listed: 8

--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/Home
"When all else fails, RTFM."

samir...@gmail.com

unread,
Oct 3, 2018, 12:40:15 PM10/3/18
to
Can you help me know any syntax in SPSS, that convert Date into Weekday.
E.g if date is appearing as 02 Oct 2018 than i want to change into Tuesday

samir...@gmail.com

unread,
Oct 3, 2018, 12:40:38 PM10/3/18
to

Ki

unread,
Oct 3, 2018, 2:18:27 PM10/3/18
to
Something like this:

*Compute here the weekday.

compute Day_of_week = xdate.WKDAY(day_of_call_R).

*1 is Sunday, 2 is Monday, etc.
*day_of_call_R should be in one of the date format.

execute.


David Marso

unread,
Oct 4, 2018, 4:28:59 PM10/4/18
to
PREVIOUSLY ANSWERED IN 2015:
A better way IMNSHO.
NUMERIC Mon Tue Wed Thu Fri Sat Sun(F1).
RECODE Mon TO Sun(ELSE=0).
VECTOR DoW=Mon TO Sun.
COMPUTE DoW(XDATE.WKDAY(date) )=1.
VALUE LABELS....
VARIABLE LABELS....
0 new messages