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 ?
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
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
Thank you very much,
all my best wishes with you in your life
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;
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.
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.