DATA Step, Macro, Functions and more

Deleting an ID with single row from a dataset containing multiple rows for each ID

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Deleting an ID with single row from a dataset containing multiple rows for each ID

 Hi,

I AM WORKING ON A SAS DATA SET  CONTAINING 1999 IDs. MOST OF THEM CONTAINS MULTIPLE ROWS (APPROXIMATELY 100000 ROWS IN TOTAL ). THERE IS ANOTHER VARIABLE IN THE DATA SET NAMED "HISTORY" HAVING VALUES "Y" AND "N".

I WANT TO DELETE THE IDs WHO HAVE ONLY ONE ROW AND HISTORY VALUE "Y". 

I AM NEW SAS USER AND COULDN'T FIGURE OUT HOW TO DO THIS. PLEASE HELP ME. ATTACHED IS A SAMPLE FILE.  

 
  
 

Accepted Solutions
Solution
‎01-24-2018 09:59 PM
PROC Star
Posts: 1,296

Re: Deleting an ID with single row from a dataset containing multiple rows for each ID

data want;

set have;

by id;

if first.id and last.id and upcase(history)='Y' then delete;

run;

 

Please don't post the same question multiple times. Thank you

View solution in original post


All Replies
Solution
‎01-24-2018 09:59 PM
PROC Star
Posts: 1,296

Re: Deleting an ID with single row from a dataset containing multiple rows for each ID

data want;

set have;

by id;

if first.id and last.id and upcase(history)='Y' then delete;

run;

 

Please don't post the same question multiple times. Thank you

Occasional Contributor
Posts: 14

Re: Deleting an ID with single row from a dataset containing multiple rows for each ID

Posted in reply to novinosrin

Thanks.  

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 102 views
  • 0 likes
  • 2 in conversation