BookmarkSubscribeRSS Feed
tinton
Fluorite | Level 6
PROC SQL; CREATE TABLE T1 AS SELECT * FROM BOOK WHERE PORTFOLIO=''; // the output will show around 1,142,678 data
PROC SQL; CREATE TABLE T2 AS SELECT DISTINCT ID FROM T1; // the output will show only 68 id- 68 rows.

If I use above code, i will only get the distinct ID in T2. How can I get all the info in T1 by select distinct id? Meaning that i want T2 to show 68 id along with all column.
2 REPLIES 2
LinusH
Tourmaline | Level 20

You can't really do that (easily) in SQL.

PROC SORT with NODUPKEY.

Be aware if you have different values on different rows for the id column, which ones you want in the output data set.

If they are all the same, you hava duplicate rows, and then you could use DISTINCT in SQL.

Data never sleeps
tinton
Fluorite | Level 6
Thanks for the reply! I've figure it out by using proc sort with nodupkey

DATA NO_DUP_TABLE; SET DUP_DATA; KEY = CATT(ID); RUN;

PROC SORT DATA= NO_DUP_TABLE NODUPKEY DUPOUT=TAB_DUP; BY KEY; RUN;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 643 views
  • 1 like
  • 2 in conversation