BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ak2011
Fluorite | Level 6
Perfect!
It works.
Thanks very much.
ak2011
Fluorite | Level 6

 

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

 

 

andreas_lds
Jade | Level 19

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.

 

 

Kurt_Bremser
Super User

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;
ak2011
Fluorite | Level 6
Thanks very much sir! Your code worked for me.
andreas_lds
Jade | Level 19

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

ak2011
Fluorite | Level 6
Sorry, I forgot to mark that as solution.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 22 replies
  • 3021 views
  • 0 likes
  • 8 in conversation