BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Table variables NR and X. I want to keep the records for each NR, where the values of X are identical.

From

NR X
10 1
10 2
10 2
10 3
10 4
10 4
10 4
10 5
.

I would like to get

NR X
10 2
10 2
10 4
10 4
10 4
.

How can that be done in a data step?
4 REPLIES 4
LinusH
Tourmaline | Level 20
You could use SET with BY nr, then using first. and last. logic in a subsetting IF statement.

/Linus
Data never sleeps
deleted_user
Not applicable
You mean BY X, I suppose?

IF FIRST.X=0 OR LAST.X=0;
LinusH
Tourmaline | Level 20
Yes, I was a bit quick.
It should be

BY nr x;

/Linus
Data never sleeps
CurtisMack
Fluorite | Level 6
Here is how I would handle this (I do it all the time for data validation purposes)
--------------------------------------------
data test;
input NR X;
cards;
10 1
10 2
10 2
10 3
10 4
10 4
10 4
10 5
;
run;

proc sort data=test;
by NR X;
run;

data dups;
set test;
by NR X;
if not(first.X and last.X);
run; Message was edited by: Curtis Mack

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 708 views
  • 0 likes
  • 3 in conversation