BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

I've two variables called Reporting_dt and premium_begin_date. If the year of the premium_begin_date is less than the Reporting_dt year then the begin date is the 1st of January of the reporting year else keep the premium_begin_date.

 

e.g. if Reporting_dt = ‘31/08/2013’ and the premium_begin_date is 01/11/2012 then the begin date = ‘01/01/2013’.

e.g. if Reporting_dt = ‘31/08/2013’ and the premium_begin_date is 01/04/2013 then the begin date = ‘01/04/2013’.

 

Appreciate if someone help me to accomplish this.

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

do like this

 

data have;
input (Reporting_dt premium_begin_date)(:ddmmyy10.);
format Reporting_dt premium_begin_date ddmmyy10.;
datalines;
31/08/2013 01/11/2012
31/08/2013 01/04/2013
;

data want;
	set have;
	begin_date=premium_begin_date;
	if year(Reporting_dt) > year(premium_begin_date) then begin_date=mdy(1, 1, year(Reporting_dt));
	format begin_date ddmmyy10.;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Classic case for using ifn() function here on a binary result:

data want;
  set have;
  begin_date=ifn(year(Reporting_dt) > year(premium_begin_date),mdy(1,1,year(Reporting_dt)),premium_begin_date);
  format begin_date ddmmyy10.;
run;

 

ballardw
Super User

@Babloo wrote:

I've two variables called Reporting_dt and premium_begin_date. If the year of the premium_begin_date is less than the Reporting_dt year then the begin date is the 1st of January of the reporting year else keep the premium_begin_date.

 

e.g. if Reporting_dt = ‘31/08/2013’ and the premium_begin_date is 01/11/2012 then the begin date = ‘01/01/2013’.

e.g. if Reporting_dt = ‘31/08/2013’ and the premium_begin_date is 01/04/2013 then the begin date = ‘01/04/2013’.

 

Appreciate if someone help me to accomplish this.


If you want to use a hard coded date in code the form is 'ddMONyy'd or 'ddMONyyyy'd. Examples: '23Feb98'd or '16May2017'd.

the D after quote tells SAS to attempt to use the value inside the quotes as a Date. The specific format is because there are so many ways to display dates and several of them are not readily identifiable in context such as "010203" which could be 02Jan2003, 01Feb2003, or 03Feb2001.

 

You may find the PDF document on here: https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... helpful for date use.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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