Help using Base SAS procedures

calculate start date based on two variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

calculate start date based on two variables

Hi I am trying to calculate a start date of employment usig the variables TimeInJobYears and TimeInJobMonths

Is there anyway that I can use these two fields to calculate when a person started work, I was thinking along the lines of todays date -  (TimeInJob
Years + TimeInJobMonths)

Any help would be greatly appreciated, Thanks


Accepted Solutions
Solution
‎03-14-2012 09:31 PM
Respected Advisor
Posts: 3,156

calculate start date based on two variables

Here is one approach, please note, I choose the beginning of the month as the date. You chould select end, middle as well.

data have;

input Name  & $12.        TimeInJobYears     TimeInJobMonths ;

cards;

John Smith      6                         4

Alan Turner     2                          8

;

data want;

set have;

start_dt=intnx('month',today(),-TimeInJobYears*12-TimeInJobMonths, 'b');

format start_dt date9.;

run;

proc print;run;

View solution in original post


All Replies
Regular Contributor
Posts: 233

calculate start date based on two variables

Can you post sample data?

Occasional Contributor
Posts: 14

calculate start date based on two variables

The TimeInJobYears and TimeInJobMonths fields hold a numeric number.

Name          TimeInJobYears     TimeInJobMonths

John Smith      6                         4

Alan Turner     2                          8

Solution
‎03-14-2012 09:31 PM
Respected Advisor
Posts: 3,156

calculate start date based on two variables

Here is one approach, please note, I choose the beginning of the month as the date. You chould select end, middle as well.

data have;

input Name  & $12.        TimeInJobYears     TimeInJobMonths ;

cards;

John Smith      6                         4

Alan Turner     2                          8

;

data want;

set have;

start_dt=intnx('month',today(),-TimeInJobYears*12-TimeInJobMonths, 'b');

format start_dt date9.;

run;

proc print;run;

Occasional Contributor
Posts: 14

calculate start date based on two variables

Thanks, that worked perfectly.

Super Contributor
Posts: 1,636

calculate start date based on two variables

how about:

data have;

input TimeInJobYears TimeInJobmonth;

cards;

5 10

6 11

;

data want;

set have;

start_date=intnx('month',today(),-(12*TimeInJobYears+TimeInJobYears),'m');

format start_date mmddyy10.;

run;

proc print;run;

                                   TimeIn       TimeIn

                     Obs    JobYears    Jobmonth    start_date

                      1         5          10       10/16/2006

                      2         6          11       09/15/2005

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 140 views
  • 0 likes
  • 4 in conversation