LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 7 Jul 2006 11:44:07 -0700
Reply-To:     "Huang, Ya" <Ya.Huang@AMYLIN.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Huang, Ya" <Ya.Huang@AMYLIN.COM>
Subject:      Re: finding minimum value in most efficient manner
Comments: To: plessthanpoinohfive <plessthanpointohfive@gmail.com>
Content-Type: text/plain; charset="us-ascii"

Not quite clear yet. If I change the testing data to this:

data hx; input id jobtitle $ months; datalines; 1 Floater 3 1 Operator 6 1 Operator 1 1 Operator 4 1 Operator 12 1 Operator 9 1 Operator 2 1 Operator 6 1 Operator 3 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 ;

What's the result you want?

-----Original Message----- From: plessthanpoinohfive [mailto:plessthanpointohfive@gmail.com] Sent: Friday, July 07, 2006 11:32 AM To: Huang, Ya; SAS-L@LISTSERV.UGA.EDU Subject: RE: finding minimum value in most efficient manner

This almost works.

This made up dataset doesn't show it, but several job entries will be the same. So, a single ID might have 8 entries of OPERATOR in a row. In our context, I'd want to sum over these for the purposes of identifying the shortest job. If one entry of OPERATOR is only for 1 month then it would get assigned the minflag even though the next 6 entries and the one before it are also OPERATOR. The result is that all my flags will tag OPERATOR.

Clear as mud?

But it's a great piece of code and I could create a dataset that sums over the consecutive jobtitles and run this code, then merge back to the original. Not efficient.

Jen

-----Original Message----- From: Ya Huang [mailto:ya.huang@AMYLIN.COM] Sent: Friday, July 07, 2006 1:23 PM To: SAS-L@LISTSERV.UGA.EDU; Jennifer Sabatier Cc: Ya Huang Subject: Re: finding minimum value in most efficient manner

Here is one using Howard's interleave trick:

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 ;

data hx; set hx (in=a_) hx (in=b_); by id; retain mina posa; if first.id and a_ then do; na_=0; nb_=0; mina=9999; end; if a_ then do; na_+1; nb_=.; if months < mina then do; mina=months; posa=na_; end; end; if b_ then do; nb_+1; na_=.; if nb_= posa then minflag=1; if nb_= posa-1 then preflag=1; output; end; drop mina posa na_ nb_; run;

proc print; run;

id jobtitle months minflag preflag

1 Floater 3 . 1 1 Operator 1 1 . 1 Crew 8 . . 1 Manager 30 . . 2 Operator 5 . 1 2 Crew 2 1 . 3 Helper 1 1 . 4 Helper 10 1 . 4 Operator 56 . . 4 Supervis 22 . . 4 Manager 10 . .

HTH

Ya

On Fri, 7 Jul 2006 12:44:01 -0400, Jen Sabatier <plessthanpointohfive@GMAIL.COM> wrote:

>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