I have the following dataset. What I want to do is that if group = treatment, i would like to drop all the records AFTER formgroup = 'surgical'
| ID | date_time | volume | formgroup | group |
| 1234 | 1/2/2020 13:12 | 53.1 | first | placebo |
| 1234 | 1/2/2020 20:12 | 32.9 | second | placebo |
| 1234 | 1/3/2020 9:12 | 23.1 | third | placebo |
| 4522 | 3/2/2020 1:19 | 20.5 | first | treatment |
| 4522 | 3/2/2020 14:10 | 24.1 | surgery | treatment |
| 4522 | 3/3/2020 13:12 | 19.2 | third | treatment |
I have no idea how to start.
| ID | date_time | volume | formgroup | group |
| 1234 | 1/2/2020 13:12 | 53.1 | first | placebo |
| 1234 | 1/2/2020 20:12 | 32.9 | second | placebo |
| 1234 | 1/3/2020 9:12 | 23.1 | third | placebo |
| 4522 | 3/2/2020 1:19 | 20.5 | first | treatment |
| 4522 | 3/2/2020 14:10 | 24.1 | surgery | treatment |
i was thinking adding if statement then delete row
data have;
input ID date_time $18. (volume formgroup group) (:$15.);
cards;
1234 1/2/2020 13:12 53.1 first placebo
1234 1/2/2020 20:12 32.9 second placebo
1234 1/3/2020 9:12 23.1 third placebo
4522 3/2/2020 1:19 20.5 first treatment
4522 3/2/2020 14:10 24.1 surgery treatment
4522 3/3/2020 13:12 19.2 third treatment
;
data want;
do until(last.id);
set have;
by id;
if _n_=0 then continue;
if formgroup='surgery' and group='treatment' then _n_=0;
output;
end;
run;
data have;
input ID date_time $18. (volume formgroup group) (:$15.);
cards;
1234 1/2/2020 13:12 53.1 first placebo
1234 1/2/2020 20:12 32.9 second placebo
1234 1/3/2020 9:12 23.1 third placebo
4522 3/2/2020 1:19 20.5 first treatment
4522 3/2/2020 14:10 24.1 surgery treatment
4522 3/3/2020 13:12 19.2 third treatment
;
data want;
do until(last.id);
set have;
by id;
if _n_=0 then continue;
if formgroup='surgery' and group='treatment' then _n_=0;
output;
end;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.