BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Solly7
Pyrite | Level 9

Hi, I need help with below.. I need to check and see which id_number(s) have used different names for transactions on the same id_number, I need to see how many different names have been used to process transactions on the same id_number( if same name

 

Data HAVE

data transactions;
input amount id_number name &:$50. ;
datalines;
100 9006 John
200 9006 Suzan
250 9006 Kurt
1000 8501 Mary
800 8501 Sean
500 7605 Drake
3000 7605 Drake
50000 5605 Solly
;

 

                                                                Data WANT

 

id_number        count_of_different_names_used

9006                                        3

8501                                        2

7605                                        1

5605                                        1

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

@DJongman , you want to count distinct names 

 

proc sql;
create table want as
select id_number,
       count(distinct name) as count_of_different_names_used
from transactions
group by id_number
order by count_of_different_names_used desc;
quit;

View solution in original post

2 REPLIES 2
DJongman
Obsidian | Level 7

Something like this?

 

proc sql;
create table want as
select id_number,
       count(*) as count_of_different_names_used
from have
group by id_number
order by count_of_different_names_used desc;
quit;
PeterClemmensen
Tourmaline | Level 20

@DJongman , you want to count distinct names 

 

proc sql;
create table want as
select id_number,
       count(distinct name) as count_of_different_names_used
from transactions
group by id_number
order by count_of_different_names_used desc;
quit;

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
  • 880 views
  • 1 like
  • 3 in conversation