Help using Base SAS procedures

Reg:Dates

Reply
Contributor
Posts: 66

Reg:Dates

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
SAS Employee
Posts: 13

Re: Reg:Dates

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;
Respected Advisor
Posts: 3,902

Re: Reg:Dates

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
Ask a Question
Discussion stats
  • 2 replies
  • 158 views
  • 0 likes
  • 3 in conversation