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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 279 views
  • 1 like
  • 2 in conversation