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

## Re: Retain obs if current jobyrout equals jobyrin of next obs

Perfect!
It works.
Thanks very much.
Fluorite | Level 6

## Counting overlap durations as one observation

Hello,

I posted this question earlier, but I still have not received any response. I have read many stuff but still no clue.

I would greatly appreciate the help of anyone who has a solution to this problem.

My  aim is to count the icode (69) for the overlap jobyrdur as 1 observation.

Jobyrdur=jobyrout-jobyrin. Icode initially is 9 but if I count the overlap jobyrdur as 1 observation final icode will be 7.

There is overlap jobyrdur for os24 jobs 2 and  3 (ie 74-78 and 78-79).

Same with Os35 jobs 5 and 6 (ie. 65-69 and 69-79). I want SAS to count the icode for 74-78 and 78-79 as 1 observation. Ie. Jobyrdur2 =79-74 = 5

Same Procedure with icode for 65-69 and 69-79: jobyrdur2=79-65=14.

My data and expected output are shown below.

Thanks in advance for your help.

ak.

data have;
input id\$ job jobyrin jobyrout jobyrdur icode ;
datalines;
os24 1 63 73 10 69
os24 2 74 78 4 69
os24 3 78 79 1 69
os24 4 80 85 5 69
os24 5 86 89 3 69
os35 4 61 64 3 69
os35 5 65 69 4 69
os35 6 69 79 10 69
os84 7 67 75 8 69
;

Expected output (data want)

inidnew\$ job jobyrin jobyrout jobyrdur2 icode;
os24 1 63 73 10 69
os24 2_3 74 79 5 69
os24 4 80 85 5 69
os24 5 86 89 3 69
os35 4 61 64 3 69
os35 5_6 65 79 14 69
os84 7 67 75 8 69

Jade | Level 19

## Re: Counting overlap durations as one observation

I am tempted to merge this question back into the old one. It is not useful at all to repost an unanswered question.

And please show what you have tried so far, @mkeintz suggested some changes to your code.

Super User

## Re: Counting overlap durations as one observation

Do not use 2-digit years. Remember the Y2K scare.

"Those who do not learn from history are doomed to repeat it".

See this:

``````data have;
input id\$ job jobyrin jobyrout jobyrdur icode \$;
datalines;
os24 1 1963 1973 10 69
os24 2 1974 1978 4 69
os24 3 1978 1979 1 69
os24 4 1980 1985 5 69
os24 5 1986 1989 3 69
os35 4 1961 1964 3 69
os35 5 1965 1969 4 69
os35 6 1969 1979 10 69
os84 7 1967 1975 8 69
;

data want;
merge
have (rename=(job=_job))
have (
firstobs=2
keep=id jobyrin
rename=(id=_id jobyrin=_jobyrin)
)
;
length job \$10;
retain job __jobyrin;
if _n_ = 1 then __jobyrin = jobyrin;
job = catx("_",job,_job);
if id ne _id or jobyrout ne _jobyrin
then do;
jobyrin = __jobyrin;
jobyrdur = jobyrout - jobyrin;
output;
job = "";
__jobyrin = _jobyrin;
end;
drop _id _job _jobyrin __jobyrin;
run;``````
Super User

## Re: Counting overlap durations as one observation

I merged all your posts dealing with the same issue into one thread. Please keep questions in one place in the future.

Fluorite | Level 6

## Re: Counting overlap durations as one observation

Thanks very much sir! Your code worked for me.
Jade | Level 19

## Re: Counting overlap durations as one observation

Wondering, why my not-that-helpful answer got marked as solution.

Fluorite | Level 6

## Re: Counting overlap durations as one observation

Sorry, I forgot to mark that as solution.
Discussion stats
• 22 replies
• 1468 views
• 0 likes
• 8 in conversation