BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
arii
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

2 REPLIES 2
Reeza
Super User

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.


 

arii
Obsidian | Level 7

Thank you, Reeza. This was helpful.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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