NODUPKEY with PROC SQL

Live Online Training : SAS Programming with 50+ Case Studies

- Explain Programming Concepts in Simple English
- Live Projects
- Scenario Based Questions
- Job Placement Assistance
- Get 10% off till Sept 25, 2017
- Batch starts from October 8, 2017

This tutorial explains how to remove duplicates by a column but returns all the columns.
data readin;
input ID Name $ Score;
cards;
1     David   45
1     David   74
2     Sam     45
2     Ram     54
3     Bane    87
3     Mary    92
3     Bane    87
4     Dane    23
5     Jenny   87
5     Ken     87
6     Simran  63
8     Priya   72
;
run;
Solution
Suppose you want to remove duplicates based on name but returns all the variables.
proc sql noprint;
create table tt (drop = row_num) as
select *, monotonic() as row_num
from readin
group by name
having row_num = min(row_num)
order by ID;
quit;
Method 2 :
proc sql noprint;
create table tt as
select name, max(ID)as ID, max(Score) as Score
from readin
group by name;
quit;
The method 2 might not be the desired output. You can also use MIN instead of MAX. 

Proc SQL Tutorials : 15 Proc SQL Tutorials


SAS Tutorials : 100 Free SAS Tutorials

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has close to 7 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like retail and commercial banking, Telecom, HR and Automotive.


While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

4 Responses to "NODUPKEY with PROC SQL"

  1. sir, please display the result of query

    ReplyDelete
  2. sir, please display the result of query

    ReplyDelete
  3. Can you please explain the code here? how it is working?

    ReplyDelete
  4. please explain
    not clear how it works

    ReplyDelete

Next → ← Prev