Hello,
How to use the weekday function based on the variable date into a calendar but with one for Saturday and so on, until 7 for Friday
Regards,
/*create dataset*/
data original_data;
format date date9.;
input date :date9.;
datalines;
28DEC2013
29DEC2013
30DEC2013
31DEC2013
01JAN2014
02JAN2014
03JAN2014
;
run;
data temp;
set original_data;
dayname=put(weekday(date),ENGLISH_DAY.);
daynumber=weekday(date);
run;
This is simply a mathematical adjustment of variable DAYNUMBER
daynumber=weekday(date);
daynumber_adjusted=daynumber+1;
if daynumber_adjusted=8 then daynumber_adjusted=1;
This is simply a mathematical adjustment of variable DAYNUMBER
daynumber=weekday(date);
daynumber_adjusted=daynumber+1;
if daynumber_adjusted=8 then daynumber_adjusted=1;
Hello @alepage,
If you need this modified WEEKDAY function multiple times in your programs, you may want to create your own function ("MYWEEKDAY"):
proc fcmp outlib=work.funcs.test;
function myweekday(date);
return(mod(weekday(date),7)+1);
endsub;
run;
Usage example:
options cmplib=work.funcs;
data _null_;
set original_data;
wd=myweekday(date);
put wd date weekdate.-l;
run;
Result:
1 Saturday, December 28, 2013 2 Sunday, December 29, 2013 3 Monday, December 30, 2013 4 Tuesday, December 31, 2013 5 Wednesday, January 1, 2014 6 Thursday, January 2, 2014 7 Friday, January 3, 2014
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.