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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 24866 views
  • 3 likes
  • 3 in conversation