Reputation: 95
So this code is from a previous person in my role (not myself) and I am trying to understand if it is completely useless or not. Still fairly new to SAS but my understanding of the Today() function is that it gives the number of days since 1/1/1960. This first statement and series of if/elses all depends on if today() returns a number less than 8, which certainly should never happen. Am i missing something or does this piece of code do nothing? (I certainty have changed code and forgotten to delete it before so they might not be insane but I'm just confused here).
data Dates;
rundate=mdy(1,1,year(today()));
if day(today()) >= 8 then do;
enddate=today()-3;
end;
else do;
if month(today()) ~= 1 then do;
if (month(today())-1) in (1,3,5,7,8,10,12) then do;
enddate=mdy(month(today())-1,31,year(today()));
end;
else if (month(today())-1) in (4,6,9,11) then do;
enddate=mdy(month(today())-1,30,year(today()));
end;
else do;
if year(today()) not in (2020,2024,2028,2032) then enddate=mdy(2,28,year(today()));
else enddate=mdy(2,29,year(today()));
end;
end;
else do;
enddate=mdy(12,31,year(today())-1);
end;
end;
Upvotes: 1
Views: 457
Reputation: 63434
You're missing a function!
if day(today()) >= 8 then do;
day()
returns the day of the month - a number from 1 to 31.
So, this only does that first part if you're not in the first week of the month - a common thing in finance for example. If it's not the first week in the month, then the enddate for the period is 3 days ago. If it IS the first week in the month, then do the more complicated logic.
Upvotes: 3