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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 382 views
  • 1 like
  • 2 in conversation