```Date: Fri, 7 Jul 2006 14:26:54 -0400 Reply-To: Venky Chakravarthy Sender: "SAS(r) Discussion" From: Venky Chakravarthy Subject: Re: finding minimum value in most efficient manner Comments: To: Jennifer Sabatier If you sort by ID and BEGINDT, that should get the right order of jobs held. What are you planning on doing with ties? The solution below takes the first minimum value and proceeds with your other rules. proc sort data = hx ; by id begindt ; run ; data solved (drop=__t: mark); array __t (1000) ; do _n_ = 1 by 1 until (last.id) ; set hx ; by id ; __t(_n_) = months ; end ; do mark = 1 by 1 until ( __t(mark) = min(of __t(*)) ) ; end ; do _n_ = 1 by 1 until (last.id) ; set hx ; by id ; if first.id and last.id then flag = 9 ; else if _n_ = mark - 1 then flag = -1 ; else if _n_ = mark then flag = 1 ; else if _n_ = mark + 1 then flag = 2 ; else flag = 0 ; output ; end ; format begindt enddt mmddyys10. ; run ; Venky Chakravarthy On Fri, 7 Jul 2006 13:29:03 -0400, plessthanpoinohfive wrote: >Whoa, that subset didn't post right... > >Let's try again.. > >id begindt enddt months WHFormTitle >1 12/29/1941 11/20/1942 1 LAB ASST >1 12/29/1941 11/20/1942 11 LAB ASST >2 1/27/1953 11/30/1953 11 >3 6/9/1952 10/24/1952 5 LABORER >3 7/14/1952 3/12/1953 6 >3 7/14/1952 3/12/1953 3 >4 1/22/1951 1/1/1953 12 1ST HPR >4 1/15/1951 1/21/1951 1 FLOATER >4 1/22/1951 1/1/1953 12 1ST HPR >4 1/22/1951 1/1/1953 1 1ST HPR >4 1/5/1953 2/15/1953 2 FLOATER >4 1/2/1953 1/4/1953 1 LAID OFF-LACK OF WORK >4 2/16/1953 2/21/1954 11 ARC FURN 1ST HPR >4 8/1/1954 10/17/1954 3 FURNACE HELPER >4 3/12/1954 5/9/1954 3 LAID OFF-LACK OF WORK >4 2/16/1953 2/21/1954 2 ARC FURN 1ST HPR >4 10/18/1954 10/24/1954 1 ARC FURN HPR >4 10/25/1954 10/16/1955 3 ARC FURN ASST. OPR >4 5/17/1954 7/31/1954 3 DETROIT FURN HPR >4 2/22/1954 3/11/1954 2 SLITTER HPR >4 5/10/1954 5/16/1954 1 SLITTER HPR >4 10/17/1955 3/2/1958 3 ARC FURN OPR >4 10/25/1954 10/16/1955 10 ARC FURN ASST. OPR >4 10/17/1955 3/2/1958 12 ARC FURN OPR >4 10/17/1955 3/2/1958 12 ARC FURN OPR >4 10/17/1955 3/2/1958 3 ARC FURN OPR >4 5/26/1958 5/8/1960 8 ARC FURN OPR >4 3/3/1958 5/25/1958 3 ARC FURN ASST. OPR >4 5/26/1958 5/8/1960 12 ARC FURN OPR >4 5/26/1958 5/8/1960 5 ARC FURN OPR >4 5/31/1960 2/25/1962 8 ARC FURN OPR >4 5/9/1960 5/30/1960 1 ARC FURN ASST. OPR >4 5/31/1960 2/25/1962 12 ARC FURN OPR >4 5/31/1960 2/25/1962 2 ARC FURN OPR >4 4/16/1962 1/6/1963 9 ARC FURN OPR >4 2/26/1962 4/15/1962 3 ARC FURN ASST. OPR >4 12/9/1963 8/8/1965 1 PLANER SAW OPR >4 4/16/1962 1/6/1963 1 ARC FURN OPR >4 1/7/1963 2/17/1963 2 ARC FURN ASST. OPR >4 2/18/1963 12/8/1963 11 BULK ANN HPR >4 12/9/1963 8/8/1965 12 PLANER SAW OPR >4 8/9/1965 8/14/1966 5 CLASS C OPR >4 12/9/1963 8/8/1965 8 PLANER SAW OPR >4 8/9/1965 8/14/1966 8 CLASS C OPR >4 8/15/1966 10/13/1968 5 DIE MAKER C >4 8/15/1966 10/13/1968 12 DIE MAKER C >4 10/14/1968 2/7/1971 3 DIE MAKER B >4 8/15/1966 10/13/1968 10 DIE MAKER C >4 10/14/1968 2/7/1971 12 DIE MAKER B >4 10/14/1968 2/7/1971 12 DIE MAKER B >4 10/14/1968 2/7/1971 2 DIE MAKER B >4 2/8/1971 3/12/1972 11 HELLER SAW OPR >4 2/8/1971 3/12/1972 3 HELLER SAW OPR >4 3/13/1972 12/15/1974 10 ASST OPR, ROLLING PLANT >4 3/13/1972 12/15/1974 12 ASST OPR, ROLLING PLANT >4 3/13/1972 12/15/1974 12 ASST OPR, ROLLING PLANT >4 12/16/1974 1/2/1983 1 TOOL INSPECTOR >4 12/16/1974 1/2/1983 12 TOOL INSPECTOR >4 12/16/1974 1/2/1983 12 TOOL INSPECTOR >4 12/16/1974 1/2/1983 12 TOOL INSPECTOR >4 12/16/1974 1/2/1983 12 TOOL INSPECTOR >4 12/16/1974 1/2/1983 12 TOOL INSPECTOR >4 12/16/1974 1/2/1983 12 TOOL INSPECTOR >4 12/16/1974 1/2/1983 12 TOOL INSPECTOR >4 12/16/1974 1/2/1983 12 TOOL INSPECTOR >4 12/16/1974 1/2/1983 1 TOOL INSPECTOR >5 6/26/1939 1/18/1942 7 >5 6/26/1939 1/18/1942 12 >5 6/26/1939 1/18/1942 12 >5 6/26/1939 1/18/1942 1 >6 10/18/1943 3/24/1944 3 >6 10/18/1943 3/24/1944 3 >7 2/1/1965 9/8/1966 11 PRODUCT SPECIALIST >7 2/1/1965 9/8/1966 9 PRODUCT SPECIALIST >8 7/2/1979 9/30/1979 3 SYSTEMS ANALYST >9 6/1/1959 2/3/1966 7 METALLURGIST >9 6/1/1959 2/3/1966 12 METALLURGIST >9 6/1/1959 2/3/1966 12 METALLURGIST >9 6/1/1959 2/3/1966 12 METALLURGIST >9 6/1/1959 2/3/1966 12 METALLURGIST >9 6/1/1959 2/3/1966 12 METALLURGIST >9 6/1/1959 2/3/1966 12 METALLURGIST >9 6/1/1959 2/3/1966 2 METALLURGIST >10 11/8/1971 2/15/1973 2 SUPERVISOR, POWDER >METALLURGY LAB >10 11/8/1971 2/15/1973 12 SUPERVISOR, POWDER >METALLURGY LAB >10 11/8/1971 2/15/1973 2 SUPERVISOR, POWDER >METALLURGY LAB >11 10/31/1966 8/31/1978 3 SUPERVISOR, FABRICATION OPRS >11 10/31/1966 8/31/1978 12 SUPERVISOR, FABRICATION OPRS >11 10/31/1966 8/31/1978 12 SUPERVISOR, FABRICATION OPRS >11 10/31/1966 8/31/1978 12 SUPERVISOR, FABRICATION OPRS >11 10/31/1966 8/31/1978 12 SUPERVISOR, FABRICATION OPRS >11 9/1/1978 3/31/1981 4 WELDING ENGINEER >11 9/1/1978 3/31/1981 12 WELDING ENGINEER >11 9/1/1978 3/31/1981 12 WELDING ENGINEER >11 4/1/1981 9/30/1981 6 RESEARCH ENGINEER >11 10/1/1981 1/31/1982 3 RESEARCH ENGINEER >11 9/1/1978 3/31/1981 3 WELDING ENGINEER >11 10/1/1981 1/31/1982 1 RESEARCH ENGINEER > >-----Original Message----- >From: Venky Chakravarthy [mailto:swovcc@HOTMAIL.COM] >Sent: Friday, July 07, 2006 1:21 PM >To: SAS-L@LISTSERV.UGA.EDU; Jennifer Sabatier >Subject: Re: finding minimum value in most efficient manner > >Can you repost your original sample with dates added instead? It makes it >easier for anyone willing to respond. Thanks. > >On Fri, 7 Jul 2006 13:00:27 -0400, plessthanpoinohfive > wrote: > >>ACK! Yes, of course. There is are begindt and enddt variables. >> >>The data are sorted by time but of course we'd need the actual dates... >> >>OK, so here is an actual subset of the real data. >> >> >>id >>begindt >>enddt >>months >>jobtitle >> >>1 >>12/29/1941 >>11/20/1942 >>1 >>LAB ASST >> >>1 >>12/29/1941 >>11/20/1942 >>11 >>LAB ASST >> > > >> >>Thanks, and sorry for being incomplete! >> >>Jen >> >> >>-----Original Message----- >>From: toby dunn [mailto:tobydunn@hotmail.com] >>Sent: Friday, July 07, 2006 12:52 PM >>To: plessthanpointohfive@GMAIL.COM; SAS-L@LISTSERV.UGA.EDU >>Subject: RE: finding minimum value in most efficient manner >> >>Jen , >> >>Is there a Date variable that we need to be aware off. Otherwise your >>before and after jobs that you say you want are arbitrary. >> >> >>Toby Dunn >> >> >> >> >> >>From: Jen Sabatier >>Reply-To: Jen Sabatier >>To: SAS-L@LISTSERV.UGA.EDU >>Subject: finding minimum value in most efficient manner >>Date: Fri, 7 Jul 2006 12:44:01 -0400 >> >>Hello, all, >> >>I have a dataset of individual's work histories. So, there is are columns >>for id, jobtitle, months. >> >>data hx; >>input id jobtitle \$ months; >>datalines; >>1 Floater 3 >>1 Operator 1 >>1 Crew 8 >>1 Manager 30 >>2 Operator 5 >>2 Crew 2 >>3 Helper 1 >>4 Helper 10 >>4 Operator 56 >>4 Supervisor 22 >>4 Manager 10 >>. >>. >>. >>; >> >> >>So, we have unequal lengths to the actual work history. Some people held >>several jobs, some just a few, and some only one. >> >>What I need to do is locate the shortest job held for each person for >people >>who held more than one job, flag it and the jobs before and/or after it. I >>will need to examine the previous and/or prior job along with the shortest >>job. If a person held only one job then I need to flag them seperately. >> >>I've tried to do this with an array but I can't make it work. I know it >>must be simple. >> >>Hope someone can help! ```

Back to: Top of message | Previous page | Main SAS-L page