If you need START and END years ,could try this too .
data have;
input id yr2010-yr2019;
datalines;
1 . . . . . . . . 1 1
2 1 1 1 . . . 1 1 1 1
3 1 1 1 1 1 . . . 1 1
4 . . . . . . 1 . . .
;
data want;
set have;
array x{*} yr: ;
temp=cats(of x{*});
pid=prxparse('/1+/');
s=1;e=length(temp);
call prxnext(pid,s,e,temp,p,l);
do while(p>0);
if maxYears<l then do;maxYears=l;start=vname(x{p}); end=vname(x{p+l-1}); end;
call prxnext(pid,s,e,temp,p,l);
end;
drop pid s e p l temp;
run;
Late homework, submitted for partial credit (less penalty for copying @Astounding's homework). 😀
data want(drop=ones);
set have;
array y yr:;
do over y;
ones=sum(ones,(y=1))*(y^=.);
maxyears=max(maxyears,ones);
end;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.