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 (November 2004, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 9 Nov 2004 00:06:29 -0500
Reply-To:   "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Subject:   Re: Defining first occurrence ..

Arthur Tabachneck wrote: > Bernie, > > While I'll definitely be chastised for suggesting using a "goto" > statement, the following should at least give you an idea of how to > solve your problem: >

data jan; mo = '01jan04'd; input clientid day1-day31; cards; 0001 1 . . 1 . 1 . 1 . . . . . . . . . . . . . . . . . . . . . . 1 0002 . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 0003 . . . . . . . . . 1 . . . . . . . 1 . . . . . . 1 . . . . . . ; run; data feb; mo = '01feb04'd; input clientid day1-day31; cards; 0001 . 1 . 1 . 1 . 1 . . . . . . . . 1 . 1 . . . . . . . . . . . . 0002 1 . 1 . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . 0003 . . . . . 1 . . . . . . . . . . . . . . 1 . . . 1 . . . . . . 0004 . . . . . . . . . . . 1 . . . . . . . . 1 . . . 1 . . . . . . ; run; data mar; mo = '01mar04'd; input clientid day1-day31; cards; 0001 . . . 1 . . . 1 1 . . . . . . . . . . . . . . . . . . . . . 1 0002 . . . . 1 . . . . . . 1 . . . . . . . . . . . . . . . . . . . 0003 . 1 . . . . . . . 1 . . . . . . . 1 . . . . . . 1 . . . . . . 0005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ; run;

> data all (keep=clientid firstdate); > set jan feb mar; > array days(31) day1-day31; > do i=1 to 31; > if days[i] eq 1 then do; > firstday=i; > goto first; > end; > end; > first: if firstday ne . then do; > firstdate=input(put(i,2.)||trim(month)||trim(year),date9.); > output; > end; > run;

Art: your goto is same as i = 1 to 31 until (days[i]) with different bound check for condition 'no day flagged in month'.

data allT / view = allT;

do until (last.clientid); set jan (in=_1) feb (in=_2) mar (in=_3) ; by clientid;

array day day1-day31;

do _n_ = 1 to dim(day) until (day[_n_]); end;

if _n_ > dim(day) then continue;

first = mo - 1 + _n_; if not qfirst then qfirst = first;

mode = 'MON'; output; end;

mo = .; first = qfirst; mode = 'QTR'; output;

format mo yymon5. first date9.;

keep clientid mo first mode; run;

-- Richard A. DeVenezia http://www.devenezia.com/


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