BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

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;
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

This is simply a mathematical adjustment of variable DAYNUMBER

 

daynumber=weekday(date);
daynumber_adjusted=daynumber+1;
if daynumber_adjusted=8 then daynumber_adjusted=1;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

This is simply a mathematical adjustment of variable DAYNUMBER

 

daynumber=weekday(date);
daynumber_adjusted=daynumber+1;
if daynumber_adjusted=8 then daynumber_adjusted=1;
--
Paige Miller
FreelanceReinh
Jade | Level 19

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 759 views
  • 1 like
  • 3 in conversation