I have the variables like Renewal_day and Renewal_month as follows and I want to calculate the Renewal_year. Variable
Renewal year can be calculated by using the variables Renewal_day and Renewal_month. If Renewal_day and Renewal_month values are past while comparing with today date value then Renewal_year should populate the value 2019 else it should be 2018.
Renewal_day | Renewal_month | Renewal_year |
1 | 2 | 2019 |
8 | 4 | 2019 |
16 | 8 | 2018 |
4 | 11 | 2018 |
6 | 5 | 2019 |
Appreciate if someone of you guide me here.
Hello!
- This should cover your requirements. Set year to this year (year(today())).
- Add a year if month is past or month is this month but date is past.
data renewal_dates;
renewal_day = 1;
renewal_month = 2;
output;
renewal_day = 8;
renewal_month = 4;
output;
renewal_day = 16;
renewal_month = 8;
output;
renewal_day = 4;
renewal_month = 11;
output;
renewal_day = 6;
renewal_month = 5;
output;
run;
data output;
set renewal_dates;
renewal_year = year(today());
if renewal_month < month(today()) then renewal_year = renewal_year + 1;
else if renewal_month = month(today()) and renewal_day < day(today()) then renewal_year = renewal_year + 1;
run;
Kind regards,
Calle
[Edited]
Something like this?
Renewal_year = year(today()) + ( mdy (Renewal_month, Renewal_day, year(today()) < today() );
year = year(today());
if mdy(month,day,year) < today() then year + 1;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.