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.
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;
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;
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.