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
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.