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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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