BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ksharp
Super User

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;
tc
Lapis Lazuli | Level 10 tc
Lapis Lazuli | Level 10

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;

 

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 16 replies
  • 4708 views
  • 14 likes
  • 7 in conversation