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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 812 views
  • 4 likes
  • 4 in conversation