how to get number of months ?

Reply
N/A
Posts: 0

how to get number of months ?

I have data in field date1 = 200702 and date= 200608

I need the result of date1-date2 = 6 months. How can i get it ?
N/A
Posts: 0

Re: how to get number of months ?

the function you're looking for is intck. when given two date values, it returns the number of specified boundaries between the two values.

if you've got actual date values, you'll probably want to use those. i assumed you didn't so there is some conversion from 200702 to '01FEB2007'd.

[pre]
data temp;
date1 = 200608;
date2 = 200702;
d1 = input(put(date1, 6.), yymmn6.);
d2 = input(put(date2,6.), yymmn6.);
format d1 d2 date9.;
months = intck('month',d1, d2);
run;
[/pre]



Message was edited by: RichardK
added link to sas documentation
trying cynthia's tip
N/A
Posts: 0

Re: how to get number of months ?

sorry about the format of the data step above...these forums don't seem to like html tags

data temp;
date1 = 200608;
date2 = 200702;
d1 = input(put(date1, 6.), yymmn6.);
d2 = input(put(date2,6.), yymmn6.);
format d1 d2 date9.;
months = intck('month',d1, d2);
run;
SAS Super FREQ
Posts: 8,645

Re: how to get number of months ?

Richard:
To code the equivalent of the PRE tags, do not use the LT and GT symbols, instead use square brackets.
'[' pre ']'
'[' /pre ']' without the spaces and quotes

[pre]
some code
some more code
[/pre]

cynthia
Post a Question
Discussion Stats
  • 3 replies
  • 346 views
  • 0 likes
  • 2 in conversation