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

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  ?

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Hi,

Please try the below code

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

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Hi,

Please try the below code

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
sayginf
Calcite | Level 5

Thank you very much,

all my best wishes with you in your life Smiley Happy

statistician13
Quartz | Level 8

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;

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 26124 views
  • 3 likes
  • 3 in conversation