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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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