BookmarkSubscribeRSS Feed
sas_
Fluorite | Level 6
Hi
i am having 2 dates i want it to be outputted in year and month for ex:

a='01jan1990'd;
b='31jul1992'd;
c= 2 years 6 months
i want the output like this 2 years 7 months in to new variable
2 REPLIES 2
DataShare
SAS Employee
try this ..

data _null_;
a='01jan1990'd;
b='31jul1992'd;
yeardiff =INTCK ( 'year', a, b ) ;
mondiff =INTCK ( 'month', a, b ) ;
mondiff = mod(mondiff,12) ;
put yeardiff 'years ' mondiff 'months' ;
run;
Patrick
Opal | Level 21
Just a variation:

data _null_;
a='01jan1990'd;
b='31jul1992'd;
c=yrdif(a,b,'ACT/ACT');
length d $ 22;
d=cat(int(c),' year(s) ',ceil(12*mod(c,1)),' month(s)');
put d=;
run;

You might want to replace the ceil() function with round() or floor().

Your example does not really say what you intend to do with fractions of months, i.e. from 01Jan to 15Feb. Would this now be 1 month or 2 months.

HTH
Patrick Message was edited by: Patrick

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1240 views
  • 0 likes
  • 3 in conversation