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

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;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 1 reply
  • 94 views
  • 0 likes
  • 2 in conversation