BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

data have;

input id Cd $ flg $ DATE1 DATE9. ;

format date1 date9.;

datalines;

 

11 chg b 13apr2019

11 chg i 11apr2019

12 chg e 6may2017

13 chg b 5jun2019

14 add d 4mar2019

14 chg y 1jan2019

;run;

 

I want to eliminate all rows where the number of rows per id is more than 1.  So In this example I would eliminate 11 and 14 and only keep 12 and 13.  Using a proc sort nodupkey would not work in this case.

 

3 REPLIES 3
Tom
Super User Tom
Super User

So only keep the IDs that do NOT have multiple rows?

data want;
  set have;
  by id;
  if first.id and last.id;
run;
novinosrin
Tourmaline | Level 20

data have;

input id Cd $ flg $ DATE1 DATE9. ;

format date1 date9.;

datalines;
11 chg b 13apr2019
11 chg i 11apr2019
12 chg e 6may2017
13 chg b 5jun2019
14 add d 4mar2019
14 chg y 1jan2019
;

proc sort data=have nouniquekeys uniqueout=singles ;
by id;
run;
Reeza
Super User
You want the NOUNIQUEKEY option with the UNIQUEOUT option within PROC SORT.

proc sort data=have nouniquekey uniqueout=want;
by id;
run;

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