Create a 'Weekday Column' Based on Date

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

Create a 'Weekday Column' Based on Date

Hi,

 

I am trying to create a new column in my data-set which would contain specific values if the date in a row falls on a particular day of the week. (e.g. Monday = 1, Tuesday = 2 etc. OR Monday = a, Tuesday = b etc.)

 

I am not too sure of how to go about this (no sample code). I would sincerely appreciate some help here.

 

  

See some parts of my data (I have more observations than these):

 

Datexxyyzz
4/27/20071235665
5/3/200734466
5/14/2007465458
5/15/2007346666
5/16/2007531186
5/17/2007314267
5/18/2007425198
5/21/2007566687

 

 

 

I have attached my sample data also.

 

 

 

Thank you in anticipation.


Accepted Solutions
Solution
‎04-30-2018 10:17 PM
Super User
Posts: 23,700

Re: Create a 'Weekday Column' Based on Date

Use the WEEKDAY() function?

This is a pretty good resource for available functions and you can find WEEKDAY() under the Date/Time category. 

http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&...

 

data demo;
do date='01Jan2018'd to '31Jan2018'd;

weekday = weekday(date);

output;

end;

run;

proc print data=demo;
format date date9.;
run;

@arii wrote:

Hi,

 

I am trying to create a new column in my data-set which would contain specific values if the date in a row falls on a particular day of the week. (e.g. Monday = 1, Tuesday = 2 etc. OR Monday = a, Tuesday = b etc.)

 

I am not too sure of how to go about this (no sample code). I would sincerely appreciate some help here.

 

  

See some parts of my data (I have more observations than these):

 

Date xx yy zz
4/27/2007 12 356 65
5/3/2007 3 44 66
5/14/2007 4 654 58
5/15/2007 34 66 66
5/16/2007 53 11 86
5/17/2007 31 42 67
5/18/2007 42 51 98
5/21/2007 56 66 87

 

 

 

I have attached my sample data also.

 

 

 

Thank you in anticipation.


 

View solution in original post


All Replies
Solution
‎04-30-2018 10:17 PM
Super User
Posts: 23,700

Re: Create a 'Weekday Column' Based on Date

Use the WEEKDAY() function?

This is a pretty good resource for available functions and you can find WEEKDAY() under the Date/Time category. 

http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&...

 

data demo;
do date='01Jan2018'd to '31Jan2018'd;

weekday = weekday(date);

output;

end;

run;

proc print data=demo;
format date date9.;
run;

@arii wrote:

Hi,

 

I am trying to create a new column in my data-set which would contain specific values if the date in a row falls on a particular day of the week. (e.g. Monday = 1, Tuesday = 2 etc. OR Monday = a, Tuesday = b etc.)

 

I am not too sure of how to go about this (no sample code). I would sincerely appreciate some help here.

 

  

See some parts of my data (I have more observations than these):

 

Date xx yy zz
4/27/2007 12 356 65
5/3/2007 3 44 66
5/14/2007 4 654 58
5/15/2007 34 66 66
5/16/2007 53 11 86
5/17/2007 31 42 67
5/18/2007 42 51 98
5/21/2007 56 66 87

 

 

 

I have attached my sample data also.

 

 

 

Thank you in anticipation.


 

Contributor
Posts: 33

Re: Create a 'Weekday Column' Based on Date

Thank you, Reeza. This was helpful.

☑ This topic is solved.

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

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