Hi all,
I would like to remove a group of observations from my dataset if the first value does not meet a certain criteria. For example, I would like to delete all entries for a certain subject ID when the first QC value is 0. If the first QC value is 1, then I do not want to delete any entries from this subject ID.
Here is an example of what my data looks like (envision additional columns with various outcome variables):
ID QC
1 1
1 0
1 1
1 1
2 0
2 0
2 1
2 1
3 1
3 0
3 1
I would like achieve the following:
ID QC
1 1
1 0
1 1
1 1
3 1
3 0
3 1
*subject with ID=2 was deleted because the first observation did not meet quality control (QC=0).
Thanks in advance!
data have;
input ID QC ;
cards;
1 1
1 0
1 1
1 1
2 0
2 0
2 1
2 1
3 1
3 0
3 1
;
data want;
set have;
by id;
retain flag;
if first.id then call missing(flag);
if first.id and qc=1 then flag=1;
if flag;
drop flag;
run;
data have;
input ID QC ;
cards;
1 1
1 0
1 1
1 1
2 0
2 0
2 1
2 1
3 1
3 0
3 1
;
data want;
set have;
by id;
retain flag;
if first.id then call missing(flag);
if first.id and qc=1 then flag=1;
if flag;
drop flag;
run;
Thanks so much!
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.