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() );

 

 

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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