BookmarkSubscribeRSS Feed
Psychoberry
Calcite | Level 5

Hello,

 

I have a very basic question I guess. I'm completely new to SAS.

Well, I have a table with 66'814 observations of start and end dates and I need to get only the weekdays. The variables are named start_date and end_date.

I tried the intck (weekday) function, but it didn't actually work the way I thought it would.

if weekday(star_date) in(1,7) then

 new = intck("weekday", start_date, end_date);

else new = intck("weekday", start_date-1, end_date);

run;

 

The error appeared that start_date and end_date aren't initalized.

All the solutions I found looked like I have to use this function above for each observation seperately, but that would took hours to do so.

 

Thank you for any help.

Best wishes.

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

The log is telling you that those variables dont exist.  Even a brief look at the code you show shows that in the weekday function you use a variable called star_day, and then in the rest of the code start_date = different.  If you want help, post test data in the form of a datastep:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

Show what you want out from that test data.  Show all your code around the block in question, show the log of that part etc.  This is not a guessing game!

Tom
Super User Tom
Super User

Explain what you want. 

Do you want to generate all of the weekdays between start and end?

Do you just want to test if start and/or end is a weekday?

data want;
  set have;
  do offset=0 to intck('day',start_date,end_date);
    new =intnx('day', start_date, offset);
    if weekday(new) in ( 2:6 ) then output;
  end;
  format new date9.;
run;

 If you want to count by week days you could use the WEEKDAY interval instead.  But then you need to check whether to start counting from zero or one based on whether your start date is a week day or not.

data want2;
  set have;
  do offset=start_date ne intnx('weekday',start_date,0) to intck('weekday',start_date,end_date);
    new =intnx('weekday', start_date, offset);
    output;
  end;
  format new date9.;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1676 views
  • 0 likes
  • 3 in conversation