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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2241 views
  • 1 like
  • 2 in conversation