BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
farshidowrang
Quartz | Level 8

Dear friends

 

I have different wells which produce oil. I like to find number of month between two maximum and minimum dates in each WELL group.

 

My dataset (_INPUT1) is:

 

WELL_NAME PROD_DATE
A 03JUL1981:00:00:00
A 09JAN1982:00:00:00
A 05SEP1992:00:00:00
A 12JAN1984:00:00:00
B 16JUL1993:00:00:00
B 18FEB1988:00:00:00
B 21NOV1986:00:00:00
B 29MAY1983:00:00:00
C 11OCT1980:00:00:00
C 12JUN1993:00:00:00
C 01DEC1988:00:00:00
C 02MAY1993:00:00:00
D 03AUG1999:00:00:00
D 03JAN1980:00:00:00
D 06NOV2005:00:00:00

 

My code is following. But it does not work:

 

proc sql;
create table _OUTPUT1 as
select WELL_NAME, PROD_DATE
intck('month',MAX(PROD_DATE),MIN(PROD_DATE)) as MTHS_PROD
FROM _INPUT1
GROUP BY WELLBORE_NAME
ORDER BY WELLBORE_NAME
;

quit;

 

Can you please help me with this?

 

Tank you very much in advance!

 

best regards

 

Farshid Owrang

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

If you want to count full months, and not the number of month boundaries crossed, you will also need option CONTINUOUS

 

intck('dtmonth', MIN(PROD_DATE), MAX(PROD_DATE), "C")

 

note : putting the min before the max will give you a positive count.

PG

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

Try DTMONTH instead of MONTH as the interval in your INTCK function. Your dates are actually datetimes so you need a datetime interval: https://documentation.sas.com/?docsetId=leforinforref&docsetTarget=p0g056g35ez8son1sfavozh0lfb3.htm&...

PGStats
Opal | Level 21

If you want to count full months, and not the number of month boundaries crossed, you will also need option CONTINUOUS

 

intck('dtmonth', MIN(PROD_DATE), MAX(PROD_DATE), "C")

 

note : putting the min before the max will give you a positive count.

PG

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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