## How To Calc Month Difference between two Numeric Columns (YYYYMM)

Solved
Occasional Contributor
Posts: 9

# How To Calc Month Difference between two Numeric Columns (YYYYMM)

Hi people,

I have searched in the google and forum but did not find the solution,

here is my problem:

I have two column in my table  date1 and date2 , columns are "numeric" and the date formats represents YYYYMM

date1         date2           datediff

---------        -----------  ----------------

201303      201310      ??

201211      201305       ??

I want to find how many month difference between these two date

according to example it must be   7 and the second row must be 6  month

but i could not find how to calculate in sas  enterprise guide 5.1  ?

Accepted Solutions
Solution
‎12-23-2013 11:18 AM
Posts: 1,147

## Re: How To Calc Month Difference between two Numeric Columns (YYYYMM)

Hi,

data have;

input date1 date2;

date1_=input(strip(put(date1,6.))||'01',yymmdd10.);

date2_=input(strip(put(date2,6.))||'01',yymmdd10.);

datediff=intck('month',date1_,date2_);

cards;

201303      201310

201211      201305

;

Thanks,

Jag

Thanks,
Jag

All Replies
Solution
‎12-23-2013 11:18 AM
Posts: 1,147

## Re: How To Calc Month Difference between two Numeric Columns (YYYYMM)

Hi,

data have;

input date1 date2;

date1_=input(strip(put(date1,6.))||'01',yymmdd10.);

date2_=input(strip(put(date2,6.))||'01',yymmdd10.);

datediff=intck('month',date1_,date2_);

cards;

201303      201310

201211      201305

;

Thanks,

Jag

Thanks,
Jag
Occasional Contributor
Posts: 9

## Re: How To Calc Month Difference between two Numeric Columns (YYYYMM)

Thank you very much,

all my best wishes with you in your life

Contributor
Posts: 57

## Re: How To Calc Month Difference between two Numeric Columns (YYYYMM)

This should do it.

```data work.cd;
input date1 date2;
datalines;
201303 201310
201211 201305
;
run;

data work.temp;
set work.cd;
datediff=intck('MONTH', input(put(date1, 6.), yymmn6.), input(put(date2, 6.), yymmn6.));
run;
```
🔒 This topic is solved and locked.