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.
Use the WEEKDAY() function?
This is a pretty good resource for available functions and you can find WEEKDAY() under the Date/Time category.
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.
Use the WEEKDAY() function?
This is a pretty good resource for available functions and you can find WEEKDAY() under the Date/Time category.
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.
Thank you, Reeza. This was helpful.
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.
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.