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

Hi!

 

For unique id, I want to keep the record; for non-unique id, I want to keep the records with non-missing date. Could anyone help with it? Thank you!!

 

What I have:

id date
1 .
2 .
2 2000-06-10
2 2002-08-26
3 2010-02-03
4 .
4 2000-06-10
4 2005-07-26
4 2016-04-03

 

What I want:

id date
1 .
2 2000-06-10
2 2002-08-26
3 2010-02-03
4 2000-06-10
4 2005-07-26
4 2016-04-03
1 ACCEPTED SOLUTION

Accepted Solutions
SASJedi
SAS Super FREQ

Try this:

data have;
	infile datalines truncover;
	input id date:yymmdd10.;
	format date yymmdd10.;
datalines;
1	.
2	.
2	2000-06-10
2	2002-08-26
3	2010-02-03
4	.
4	2000-06-10
4	2005-07-26
4	2016-04-03
;

/* The data must be sorted at least by ID */
proc sort data=have;
	by id date;
run;

data want;
	set have;
	by id;
	if (first.id and last.id)
		or not missing(date);
run;

My result:

Want

Obs id date
1 1 .
2 2 2000-06-10
3 2 2002-08-26
4 3 2010-02-03
5 4 2000-06-10
6 4 2005-07-26
7 4 2016-04-03
Check out my Jedi SAS Tricks for SAS Users

View solution in original post

1 REPLY 1
SASJedi
SAS Super FREQ

Try this:

data have;
	infile datalines truncover;
	input id date:yymmdd10.;
	format date yymmdd10.;
datalines;
1	.
2	.
2	2000-06-10
2	2002-08-26
3	2010-02-03
4	.
4	2000-06-10
4	2005-07-26
4	2016-04-03
;

/* The data must be sorted at least by ID */
proc sort data=have;
	by id date;
run;

data want;
	set have;
	by id;
	if (first.id and last.id)
		or not missing(date);
run;

My result:

Want

Obs id date
1 1 .
2 2 2000-06-10
3 2 2002-08-26
4 3 2010-02-03
5 4 2000-06-10
6 4 2005-07-26
7 4 2016-04-03
Check out my Jedi SAS Tricks for SAS Users

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 393 views
  • 3 likes
  • 2 in conversation