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.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 1 reply
  • 174 views
  • 0 likes
  • 2 in conversation