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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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