BookmarkSubscribeRSS Feed
jduffy
Calcite | Level 5

I have 100k obs of data with the variable NAME.   Looks as follows.

 

OBS

NAME

1

John

2

Mary

3

Joe

4

John

5

Steve

6

Joan

7

John

8

Mary

9

Steve

10

shawn

 

What I would like to do is create a list that has each unique value of the variable NAME.   From the sample above the output list would be...

 

Obs

Name

1

John

2

Mary

3

Joe

4

Steve

5

Joan

6

Shawn

 

I only want to capture each unique value of the variable NAME.   I've thought of doing this using a STACK feature in other languages and read up on the ARRAY function in SAS.  I need to be able to read my input dataset capture the value of NAME and examine it against a stack or array to see if I have already stored its value.  

 

Is there a better way of doing this?   Is there a PROCEDURE that will do this? I'm thinking the DATA Step is the best approach but wanted to share my problem with this forum.

 

Best regards

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

please try the proc sort procedure with the nodupkey option to remove the duplicates.

 

 

proc sort data=have out=want nodupkey;
by name;
run;

 

Thanks,
Jag
Astounding
PROC Star

The suggested SORT will work, as will PROC SQL using SELECT DISTINCT.

 

Before that, however,  you have to decide what makes a name different?  You have "shawn" in your sample data.  Is "shawn" different than "Shawn" ?  You might want to account for capitalization before applying a procedure.

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1071 views
  • 3 likes
  • 3 in conversation