BookmarkSubscribeRSS Feed
QLi
Fluorite | Level 6 QLi
Fluorite | Level 6
Hi,

I need to calculate the number of months between two dates.
the data like this:

data a;
informat date9.;
input opendate;
cards;
Hh Date Active
09-Nov-84
01-Jan-78
15-Jun-87
10-May-82
01-Nov-72
18-May-94
29-Apr-85
18-Jul-97
02-Feb-96
16-Aug-88
01-Nov-99
22-Jun-00
10-Aug-90
08-May-98
01-Jan-78
08-Oct-02
02-Jan-89
20-Feb-04
04-Apr-75
20-Aug-04
23-Jun-04
16-Jul-04
01-Jun-92
25-Aug-94
06-Mar-07
15-May-06
05-Mar-07
26-Aug-02
18-Nov-01
11-Jun-96
03-Dec-99
30-Jul-08
16-Apr-07
14-May-07
18-Jun-08
13-Jul-07
06-Dec-02
01-Jan-78
05-Oct-95
06-May-08
04-Sep-98
19-Sep-09
31-Oct-08
01-Nov-08
01-Oct-92
20-Sep-07
30-May-97
22-May-08
24-Jul-09
01-Dec-89
;
run;

I need to calculate how many monthes between open date to now. Could someone help me out ?

Thanks,

Ching


T
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Yes, use the INTCK function along with your date-variable and the TODAY() function as one of your arguments.

Scott Barry
SBBWorks, Inc.

Recommended Google advanced search arguments, this topic/post:

using sas dates site:sas.com

comparing sas dates intck site:sas.com
QLi
Fluorite | Level 6 QLi
Fluorite | Level 6
Thanks for your feedback.

I know it is easy to calculate for single date variable. How to use intck function in Data Step to calculate many date vairables.

mage=INTCK(’MONTH’,’date’D,’30Oct2009’D)

many thanks,
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You can declare and use an ARRAY which would list your "date variables", as shown below:

DATA _NULL_;
ARRAY ADATES (*) DATE1-DATE3;
FORMAT DATE: DATE9.;
* LOAD UP SOME DATE VARIABLES FOR AN DEMO. ;
DO MN=1 TO DIM(ADATES);
ADATES(MN) = INTNX('MONTH',TODAY(),MN,'SAMEDAY');
END;
DO I=1 TO DIM(ADATES);
* DO SOME CODE FOR EACH VARIABLE IN THE ARRAY. ;
END;
PUTLOG _ALL_;
RUN;

Scott Barry
SBBWorks, Inc.

Recommended Google advanced search argument, this topic/post:

data step array processing site:sas.com
P_J
Calcite | Level 5 P_J
Calcite | Level 5
Please try this one.

data a;
input opendate anydtdte.;
format opendate date9.;
today = put(today(), date9.);
mth = intck("month", opendate, today());
cards;
09-Nov-84
01-Jan-78
15-Jun-87
10-May-82
01-Nov-72
18-May-94
29-Apr-85
18-Jul-97
02-Feb-96
16-Aug-88
01-Nov-99
22-Jun-00
10-Aug-90
08-May-98
01-Jan-78
08-Oct-02
02-Jan-89
20-Feb-04
04-Apr-75
20-Aug-04
23-Jun-04
16-Jul-04
01-Jun-92
25-Aug-94
06-Mar-07
15-May-06
05-Mar-07
26-Aug-02
18-Nov-01
11-Jun-96
03-Dec-99
30-Jul-08
16-Apr-07
14-May-07
18-Jun-08
13-Jul-07
06-Dec-02
01-Jan-78
05-Oct-95
06-May-08
04-Sep-98
19-Sep-09
31-Oct-08
01-Nov-08
01-Oct-92
20-Sep-07
30-May-97
22-May-08
24-Jul-09
01-Dec-89
;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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