Date: Tue, 9 Nov 2004 00:06:29 -0500 "Richard A. DeVenezia" "SAS(r) Discussion" "Richard A. DeVenezia" 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