Subset for multiple observations per subject

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

Subset for multiple observations per subject

Dear SAS Users,

My data set looks something like this:

ID     Response

1     A

1     B

1     C

2     B

3     C

3     C

3     A

4     B

4     B

5     C

5     C

5     C

I would like to output only the subjects who have do not have response=A in any of their observations.  For my data lines, I would like to see this output:

ID     Response

2     B

4     B

4     B

5     C

5     C

5     C

Could someone please suggest some code to subset for multiple observations per subject? Thank you.


Accepted Solutions
Solution
‎07-10-2013 03:51 PM
Regular Contributor
Posts: 180

Re: Subset for multiple observations per subject

Try this:

Data have;
  input ID Response $;
cards;
1     A
1     B
1     C
2     B
3     C
3     C
3     A
4     B
4     B
5     C
5     C
5     C
;
run;

proc sql;
  create table want as
  select *
  from have
  where id not in (select distinct id from have where response='A');
quit;

Regards,

View solution in original post


All Replies
Contributor
Posts: 56

Re: Subset for multiple observations per subject

as per my understanding,,,

if response ne 'A';

or

if response in('B','C');

shiva

Contributor
Posts: 44

Re: Subset for multiple observations per subject

Posted in reply to shivakrishna

These statements still return subjects with A in at least one observation:

ID     Response

1     B

1     C

2     B

3     C

3     C

4     B

4     B

5     C

5     C

5     C

I would like to output only ID's 2,4, and 5 because they don't contain A in any datalines.  Thank you. 

Contributor
Posts: 56

Re: Subset for multiple observations per subject

if id in(2,4,5);

shiva

Solution
‎07-10-2013 03:51 PM
Regular Contributor
Posts: 180

Re: Subset for multiple observations per subject

Try this:

Data have;
  input ID Response $;
cards;
1     A
1     B
1     C
2     B
3     C
3     C
3     A
4     B
4     B
5     C
5     C
5     C
;
run;

proc sql;
  create table want as
  select *
  from have
  where id not in (select distinct id from have where response='A');
quit;

Regards,

Contributor
Posts: 44

Re: Subset for multiple observations per subject

Cool, that works! Thank you.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 268 views
  • 0 likes
  • 3 in conversation