BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
zihdonv19
Quartz | Level 8

I want to keep all rows of same id as long as this id has at least one record of type=2.

 

The dataset I have is:

data have;
   input id 	type	visit_date :yymmdd10.;
   format visit_date yymmdd10.;
datalines;
1 	1 	2000-01-01
1 	2 	2005-01-02
1 	2 	2006-01-03
1 	3 	2007-01-04
1 	5 	2010-01-05
2 	. 	2000-01-06
2 	. 	2000-01-07
2 	. 	2000-01-08
3 	2 	2001-01-09
3 	. 	2006-01-10
3 	2 	2007-01-11
3 	. 	2008-01-12
4 	. 	2006-01-10
4 	3 	2007-01-11
4 	1 	2008-01-12
5 	2 	2007-01-11
5 	2 	2008-01-12
5 	2 	2009-01-10
5 	2 	2010-01-11
6 	2 	2002-01-12
6 	1 	2003-01-10
6 	. 	2004-01-11
;

 

What I want:

data have;
   input id 	type	visit_date :yymmdd10.;
   format visit_date yymmdd10.;
datalines;
1 	1 	2000-01-01
1 	2 	2005-01-02
1 	2 	2006-01-03
1 	3 	2007-01-04
1 	5 	2010-01-05
3 	2 	2001-01-09
3 	. 	2006-01-10
3 	2 	2007-01-11
3 	. 	2008-01-12
5 	2 	2007-01-11
5 	2 	2008-01-12
5 	2 	2009-01-10
5 	2 	2010-01-11
6 	2 	2002-01-12
6 	1 	2003-01-10
6 	. 	2004-01-11
;
1 ACCEPTED SOLUTION

Accepted Solutions
HB
Barite | Level 11 HB
Barite | Level 11

There are multiple ways to do this:

 

Try:

proc sql;
	select * 
	from have
	where id in 
		(select distinct id
		from have
		where type = 2);
quit;

View solution in original post

1 REPLY 1
HB
Barite | Level 11 HB
Barite | Level 11

There are multiple ways to do this:

 

Try:

proc sql;
	select * 
	from have
	where id in 
		(select distinct id
		from have
		where type = 2);
quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 499 views
  • 0 likes
  • 2 in conversation