Returning day of week from date variable in Data step

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Returning day of week from date variable in Data step

I have a dozen date variables formatted as DATE9.  I need to create variables that connect the dates to the corresponding day of the week.  I was trying something like the following, using the date variable "startdate":

if startdate = 05/30/2013  then startday = 4; *4 = Thursday;

But although it doesn't produce an error, it doesn't work.  No cases have a value for startday, even though many have a startdate matching the criteria.  (And even if it did, it would take a lot of code to do this for every possible date.)

I've been looking through the help files and see that the dates are saved as datetime, but I can't figure out how to use that.  Ideally I want to do something like:

startdateday = *GETDAYCOMMAND*(startdate);

if startdateday = "Thursday" then startday = 4;

if startdateday = "Wednesday" then startday = 3;

etc.

Or if this isn't possible, I can do the dates one by one if I could figure out how to say "05/30/2013" the right way.

Any ideas would be greatly appreciated, thanks!


Accepted Solutions
Solution
‎07-23-2013 08:35 PM
Respected Advisor
Posts: 4,925

Re: Returning day of week from date variable in Data step

Use the function WEEKDAY.

"The WEEKDAY function produces an integer that represents the day of the week,

where 1=Sunday, 2=Monday, ..., 7=Saturday."

PG

PG

View solution in original post


All Replies
Solution
‎07-23-2013 08:35 PM
Respected Advisor
Posts: 4,925

Re: Returning day of week from date variable in Data step

Use the function WEEKDAY.

"The WEEKDAY function produces an integer that represents the day of the week,

where 1=Sunday, 2=Monday, ..., 7=Saturday."

PG

PG
New Contributor
Posts: 2

Re: Returning day of week from date variable in Data step

Perfect, thank you!

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 209 views
  • 0 likes
  • 2 in conversation