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;

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
  • 2 replies
  • 2831 views
  • 1 like
  • 2 in conversation