BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
monday89
Fluorite | Level 6

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 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20

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;
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1481 views
  • 0 likes
  • 2 in conversation