BookmarkSubscribeRSS Feed
Tom
Super User Tom
Super User

Again I am not sure why it matters what numbers are used.  I would also push back on that requirement to see if there is any basis for it.

 

You can always renumber.

proc sort data=test;
  by usubjid aellt astdt fake_end ;
run;

data step1 ;
  set test ;
  by usubjid aellt ;
  if first.usubjid then GROUP=0;
  if first.aellt or (astdt > lag(aendt)) then GROUP+1;
run;

proc sql ;
create table renumber as  
  select usubjid,GROUP,aellt,min(astdt) as first_date format=date9.
  from step1
  group by usubjid,GROUP,aellt
  order by usubjid,first_date,aellt
;
quit;

data renumber;
  set renumber;
  by usubjid first_date aellt;
  if first.usubjid then AJOINID=0;
  AJOINID+1;
  keep usubjid GROUP AJOINID;
run;

proc sort data=renumber;
  by usubjid group;
run;

data want;
  merge step1 renumber;
  by usubjid group;
run;

proc sort data=want;
  by usubjid astdt aellt fake_end ;
run;

proc print;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 15 replies
  • 1478 views
  • 1 like
  • 3 in conversation