- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Or try this and let us know what happens:
week = intnx('week', input(date, yymmdd10.),0,'b');
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please post the complete log of that step. Use the </> button to post it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It should be a numeric variable with a format of yymmdd10.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Or try this and let us know what happens:
week = intnx('week', input(date, yymmdd10.),0,'b');
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes, it worked. Thanks a lot!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.