BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MCB
Calcite | Level 5 MCB
Calcite | Level 5

My data is the following:

 

ID BirthYear BirthMonth PensionYear PensionMonth
1 1944 1 2009 8
2 1947 2 2012 7
3 1941 10 2007 5

 

The table above shows when the person is born and when the person retired. I need to create two additional variables which show retirement age as 1. number of years and 2. number of month. For example I need to calculate that ID 1 has retired at the age of 65 years and 8 month.

 

ID BirthYear BirthMonth PensionYear PensionMonth PensionAgeYears PensionAgeMonth
1 1944 1 2009 8 65 8
2 1947 2 2012 7 65 5
3 1941 10 2007 5 65 7

  

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Something like this?

 

data mydata;
   input ID $ BirthYear BirthMonth PensionYear PensionMonth;
   datalines;
1 1944 1  2009 8
2 1947 2  2012 7
3 1941 10 2007 5
;

data PensionData;
   set mydata;
   Birthdate = mdy(BirthMonth,1,BirthYear);
   Pensiondate = mdy(PensionMonth,1,PensionYear);

   PensionAgeYears = intck('year', Birthdate, Pensiondate, 'c');
   PensionAgeMonth = intck('month', intnx('year', Birthdate, PensionAgeYears, 's'), Pensiondate, 'c');

   format Birthdate Pensiondate ddmmyy10.;
   drop Birthdate Pensiondate;
run;

http://sasnrd.com/date-basics/ 

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Something like this?

 

data mydata;
   input ID $ BirthYear BirthMonth PensionYear PensionMonth;
   datalines;
1 1944 1  2009 8
2 1947 2  2012 7
3 1941 10 2007 5
;

data PensionData;
   set mydata;
   Birthdate = mdy(BirthMonth,1,BirthYear);
   Pensiondate = mdy(PensionMonth,1,PensionYear);

   PensionAgeYears = intck('year', Birthdate, Pensiondate, 'c');
   PensionAgeMonth = intck('month', intnx('year', Birthdate, PensionAgeYears, 's'), Pensiondate, 'c');

   format Birthdate Pensiondate ddmmyy10.;
   drop Birthdate Pensiondate;
run;

http://sasnrd.com/date-basics/ 

PeterClemmensen
Tourmaline | Level 20

Anytime, Glad I could help 🙂 Please mark it as a solution

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 1185 views
  • 1 like
  • 2 in conversation