Desktop productivity for business analysts and programmers

Day of the week variable

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

Day of the week variable

Let's say I have this kind of data:

YearMonthDayHour
200911223
200911322
200921613
20103411

 

Is there a way I can make a new variable called Weekday where 1=Monday 2=Tuesday etc.?


Accepted Solutions
Solution
3 weeks ago
PROC Star
Posts: 1,410

Re: Day of the week variable

[ Edited ]
data have;
input Year	Month	Day	Hour;
datalines;
2009	1	12	23
2009	1	13	22
2009	2	16	13
2010	3	4	11
;

data want;
   set have;
   date=mdy(Month, Day, Year);
   WeekDay=weekday(date)-1;
   format date date9.;
run;

EDIT: Subtracted 1 when using the Weekday Function. Weekday function assumes sunday=1. 

View solution in original post


All Replies
Solution
3 weeks ago
PROC Star
Posts: 1,410

Re: Day of the week variable

[ Edited ]
data have;
input Year	Month	Day	Hour;
datalines;
2009	1	12	23
2009	1	13	22
2009	2	16	13
2010	3	4	11
;

data want;
   set have;
   date=mdy(Month, Day, Year);
   WeekDay=weekday(date)-1;
   format date date9.;
run;

EDIT: Subtracted 1 when using the Weekday Function. Weekday function assumes sunday=1. 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 121 views
  • 2 likes
  • 2 in conversation