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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.