BookmarkSubscribeRSS Feed
mansour_ib_sas
Pyrite | Level 9

Hello,

 

I can't resolve this problem.

I try to have for each given date, Monday as the start of the week and Friday as the day of the weekend.

The error is made on the first day of the month.

The following example illustrates the error.

Thank you for your help.

 

data _null_;
   date = '03feb2020'd;
   firstday = intnx('week.2',date,-1);
   lastday  = intnx('week.6',date ,-1);
   put (date firstday lastday) (= date9.) ;
   
run;

Log

 73         data _null_;
 74            date = '03feb2020'd;
 75            firstday = intnx('week.2',date,-1);
 76            lastday  = intnx('week.6',date ,-1);
 77            put (date firstday lastday) (= date9.) ;
 78         
 79         run;
 
 date=03FEB2020 firstday=27JAN2020 lastday=24JAN2020
3 REPLIES 3
PaigeMiller
Diamond | Level 26

You haven't described the desired output.

--
Paige Miller
Ksharp
Super User

As Paige said, post the output you want .

 

data _null_;
   date = '03feb2020'd;
   firstday = intnx('week.2',date,-1);
   lastday  = intnx('week.6',date ,0);
   put (date firstday lastday) (= date9.) ;
   
run;
Reeza
Super User
I think -1 is the issue. That moves it to the previous week, but if you want it within the same week that should be 0.

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
  • 3 replies
  • 971 views
  • 1 like
  • 4 in conversation