BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

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.

3 REPLIES 3
CalleJ
Fluorite | Level 6

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

ChrisNZ
Tourmaline | Level 20

 

[Edited]

Something like this?

 

Renewal_year = year(today()) + ( mdy (Renewal_month, Renewal_day, year(today()) < today() );

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1420 views
  • 4 likes
  • 4 in conversation