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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1043 views
  • 0 likes
  • 2 in conversation