BookmarkSubscribeRSS Feed
Midi
Obsidian | Level 7

Hello Everyone , So I have This Table :

 

OssClient_IDCode_IDType_IDMasFAM_ID             
12389551723895517143530

 

    .       
22389551723895518143825     .       
32389551723895519143315             
42389551723895520141515     .       
52389552223895521139815     .      .
62389552223895522139126     .    

 

 .
72389552223895523143530             
82389552323895524143530

 

    .       
92389552323895525143825     .       
102389552323895526143315             
112389552423895520141515     .       
122389552423895521139815     .      .
132389552423895522139126     .    

 

 .

 

And I want To get This Output :

 

Client_ID

FAM_ID

     30

FAM_ID

25

FAM_ID

15

FAM_ID

26

              
      

 

    .       
           .       
23895517      11     3      1              
           .       
           .      .
 

 

         .    

 

 .

 

So , basically what it does is , it looks for every FAM_ID and then counts the distinct Mas for every Client .

 

Any Help Would Be Much Appreciated , Thank you.

1 REPLY 1
Reeza
Super User

SAS doesn't have procs that do count distinct except for PROC SQL, so first do the distinct calculation and then use PROC FREQ/TABULATE. Do you need a table/data set or do you need a report?

 

proc sql;
create table distinct_counts as
select client_id, fam_id, count(distinct MAS) as distinct_MAS
from have
group by client_id, fam_id;
quit;

proc transpose data=distinct_counts out=want1 prefix=famID_;
by client_id;
id fam_id;
var distinct_MAS;
run;

proc print data=want1;
run;

@Midi wrote:

Hello Everyone , So I have This Table :

 

Oss Client_ID Code_ID Type_ID Mas FAM_ID                          
1 23895517 23895517 143 5 30

 

        .              
2 23895517 23895518 143 8 25           .              
3 23895517 23895519 143 3 15                          
4 23895517 23895520 141 5 15           .              
5 23895522 23895521 139 8 15           .             .
6 23895522 23895522 139 1 26           .        

 

  .
7 23895522 23895523 143 5 30                          
8 23895523 23895524 143 5 30

 

        .              
9 23895523 23895525 143 8 25           .              
10 23895523 23895526 143 3 15                          
11 23895524 23895520 141 5 15           .              
12 23895524 23895521 139 8 15           .             .
13 23895524 23895522 139 1 26           .        

 

  .

 

And I want To get This Output :

 

Client_ID

FAM_ID

     30

FAM_ID

25

FAM_ID

15

FAM_ID

26

                           
           

 

        .              
                      .              
23895517       1 1      3       1                            
                      .              
                      .             .
 

 

                  .        

 

  .

 

So , basically what it does is , it looks for every FAM_ID and then counts the distinct Mas for every Client .

 

Any Help Would Be Much Appreciated , Thank you.


 

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!

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
  • 1 reply
  • 487 views
  • 0 likes
  • 2 in conversation