data abcd;
input ID;
cards;
1
1
1
2
2
1
2
3
3
3
;
run;
answer would be like below :
Output:
1
1
1
2
2
3
3
3
I think what you mean is to keep only the first group of records for any given ID:
data abcd;
input ID;
cards;
1
1
1
2
2
1
2
3
3
3
;
run;
data want;
set abcd;
by id notsorted;
if _n_=1 then do;
declare hash h();
h.definekey('id');
h.definedone();
end;
if h.check()=0 then delete;
if last.id then h.add();
run;
I think what you mean is to keep only the first group of records for any given ID:
data abcd;
input ID;
cards;
1
1
1
2
2
1
2
3
3
3
;
run;
data want;
set abcd;
by id notsorted;
if _n_=1 then do;
declare hash h();
h.definekey('id');
h.definedone();
end;
if h.check()=0 then delete;
if last.id then h.add();
run;
Thanks it works
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.