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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.