I am trying to find the starting date of the week of a date value.
For example, 2021-04-30 will return 2021-04-26(1st date of the week).
i am using the code:
start_week = intnx('week',date,0,'b');
format start_week date10.;
But this is returning null value.
Can anyone help me.
I am trying to find the starting date of the week of a date value.
For example, 2021-04-30 will return 2021-04-26(1st date of the week).
i am using the code:
start_week = intnx('week',date,0,'b');
format start_week date10.;
But this is returning null value.
Can anyone help me.
Your code seems fine. I think it is the input value of date.
See the code below.
data _null_;
start_week = intnx('week', today(), 0, 'b');
format start_week date10.;
put start_week=;
run;
Please post the complete log of that step. Use the </> button to post it.
If date is missing the result will be missing.
If date is character you should see "invalid data" such as this:
104 data junk; 105 date ='2021-01-01'; 106 week = intnx('week', date,1,'b'); 107 run; NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 106:25 NOTE: Invalid numeric data, date='2021-01-01' , at line 106 column 25. date=2021-01-01 week=. _ERROR_=1 _N_=1
If date is actually a datetime value you should get an invalid message like this because the values of datetimes when used as a date without appropriate conversion or options often exceed the range of values the date related functions will handle.
108 data junk; 109 date ='01JAN2021:12:15:00'dt; 110 put date= datetime18.; 111 week = intnx('week', date,1,'b'); 112 run; date=01JAN21:12:15:00 NOTE: Invalid argument to function INTNX('week',1925122500,1,'b') at line 111 column 11. date=1925122500 week=. _ERROR_=1 _N_=1 NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 111:11
All of these cases will return missing values from the intnx function.
So, which values are you actually supplying to the function? And are you getting notes in the log?
Yes, it worked. Thanks a lot!!
@anandmgjsa wrote:
Yes, I am getting the notes mentioned by you. But the input used by me is date itself not datetime. Or I am missing something. Please clarify.
That means that you really have to follow @Kurt_Bremser's recommendation and show us your log. Copy the text for the entire data step plus messages from the log. On the forum open a text box by clicking on the </> icon above the message window and paste.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.