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-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!

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.

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