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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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