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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.