Hello, I am looking to delete all initial observations of VAR, within each ID group, until we hit the first 0. If none of the values within an ID group are 0, then I want to remove all of them.
Here is a example of the data I have. I would like to remove observations 1, 10, 11, 12, 13 and 14
Thanks in advance!
observation | ID | VAR |
1 | 1 | 1 |
2 | 1 | 0 |
3 | 1 | 1 |
4 | 1 | 0 |
5 | 1 | 1 |
6 | 1 | 1 |
7 | 2 | 0 |
8 | 2 | 1 |
9 | 2 | 0 |
10 | 3 | 1 |
11 | 3 | 1 |
12 | 3 | 1 |
13 | 4 | 1 |
14 | 4 | 1 |
15 | 4 | 0 |
16 | 4 | 1 |
data want;
set have;
by id;
retain flag;
if first.id then flag = 0;
if var = 0 then flag = 1;
if flag;
drop flag;
run;
data want;
do until (last.var);
set have;
by id var notsorted ;
if first.id and var=1 then flag=1;
if flag ne 1 then output ;
end;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: