- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data housekeeping_Data;
input Date DATE10. ;
format Date DATE10.;
cards;
26DEC2020
25DEC2020
27DEC2020
28DEC2020
29DEC2020
30DEC2020
17NOV2020
15NOV2020
01NOV2020
11NOV2020
;
run;
Hi everyone ,
Above is the input data now I want that the observations which are 5 days old from my Today() should be deleted/removed whenever I run the date.
FYI : I used, five_mo_ago = intnx('date',today(), -5 ,same); but It is not working.
Any other approach is welcomed.
output should be like below when today is 27th Dec'2020:
Obs | Date |
1 | 26-Dec-20 |
2 | 25-Dec-20 |
3 | 27-Dec-20 |
4 | 28-Dec-20 |
5 | 29-Dec-20 |
6 | 30-Dec-20 |
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why did you calculate a date that is five days before TODAY but then not use it.
Note that SAS stores dates as number of days. So to get a difference in days just subtract two date values.
If you have a date, X, and another date, Y then the difference in days is X-Y. If the difference is negative then Y is after X. If the difference is positive then X is after Y.
So if today is 15DEC2020 then 5 day ago would be 10DEC2020, which you can calculate by using (today()-5). If you want to remove values with dates before 10DEC2020 then code something like:
if date < (today()-5) then delete;
If you also want to delete the dates that fall on 10DEC2020 then use <= instead of = in the comparison.
What do you want to do with observations where DATE is missing? SAS will treat missing values as less than any actual number so observations with missing value of DATE will be deleted by the statement above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can try
five_mo_ago = intnx('day',today(), -5);
Other than that, I'm afraid I don't understand your problem. Do you mean you want to delete records where variable DATE is greater than 5 days old? Or do you mean something else?
Please don't ever say "but It is not working" and provide no other information. We can't help you if you provide no other information. Please do show us the LOG for the code that isn't working (all of it, 100%, the code as it appears in the LOG, the ERRORs, WARNINGs, NOTEs, in the sequence it appears in the log, with nothing chopped out).
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@PaigeMiller wrote:
You can try
five_mo_ago = intnx('day',today(), -5);
Other than that, I'm afraid I don't understand your problem. Do you mean you want to delete records where variable DATE is greater than 5 days old? Or do you mean something else?
Please don't ever say "but It is not working" and provide no other information. We can't help you if you provide no other information. Please do show us the LOG for the code that isn't working (all of it, 100%, the code as it appears in the LOG, the ERRORs, WARNINGs, NOTEs, in the sequence it appears in the log, with nothing chopped out).
I did not pasted because was not able to code much on this but still I am keeping my code below. :
data final;
set housekeeping_data;
five_days_ago = intnx('day',today(), -5);
if date < Today() then delete /* HERE want that the observations which are 5 days old from my Today()
should be deleted/removed*/;
drop five_days_Ago;
proc print;
run;
Yes, Do you mean you want to delete records where variable DATE is gt than 5 days old from today.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
if date < five_days_ago then delete;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why did you calculate a date that is five days before TODAY but then not use it.
Note that SAS stores dates as number of days. So to get a difference in days just subtract two date values.
If you have a date, X, and another date, Y then the difference in days is X-Y. If the difference is negative then Y is after X. If the difference is positive then X is after Y.
So if today is 15DEC2020 then 5 day ago would be 10DEC2020, which you can calculate by using (today()-5). If you want to remove values with dates before 10DEC2020 then code something like:
if date < (today()-5) then delete;
If you also want to delete the dates that fall on 10DEC2020 then use <= instead of = in the comparison.
What do you want to do with observations where DATE is missing? SAS will treat missing values as less than any actual number so observations with missing value of DATE will be deleted by the statement above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
if date < (today()-5) then delete; this worked. Thanks