BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

I have a data set similar to this. I would like to get Alert case by anatomic site of inf. 

Alert CasesAnatomic Site
Alert 1Urethral
Alertr 2Pharyngeal
Alert 3Pharyngeal
Alert 4Urethral
Alert 5Cervix
Alert 5Pharyngeal 
Alert 6Pharyngeal
Alert 7Rectum
Alert 8Urethral 
Alert 8Rectum
Alert 9Urethral
Alert 10Urethral
Alert 10Pharyngeal
Alert 11Urethral
Alert 12Cervical
Alert 13Urethral
Alert 13Rectum
Alert 14Urethral
Alert 15Urethral

The output I want is something like this

 UrethraPharyngealPhryngeal & UrethraCervixCervix &Pharyngeal Recturm& Urethra
Alert Cases5020 254
2 REPLIES 2
hashman
Ammonite | Level 13

@Dhana18 :

Your description offers a very vague idea of what you're trying to do, especially since your proposed output doesn't compute vis-a-vis your sample input. As a wild guess, are you trying to:

  • just get the frequencies of the values in the column "Anatomic Site" and write a report to display them horizontally?
  • generate a 1-record data set looking the way you've shown?  

If it's the former, you can use proc TABULATE, for example:

data have ;                                  
  input Alert_Cases & $ Anatomic_Site :$32. ;
  cards ;                                    
Alert 1      Urethral                        
Alert 2      Pharyngeal                      
Alert 3      Pharyngeal                      
Alert 4      Urethral                        
Alert 5      Cervix                          
Alert 5      Pharyngeal                      
Alert 6      Pharyngeal                      
Alert 7      Rectum                          
Alert 8      Urethral                        
Alert 8      Rectum                          
Alert 9      Urethral                        
Alert 10     Urethral                        
Alert 10     Pharyngeal                      
Alert 11     Urethral                        
Alert 12     Cervical                        
Alert 13     Urethral                        
Alert 13     Rectum                          
Alert 14     Urethral                        
Alert 15     Urethral                        
;                                            
run ;                                        
                                             
proc tabulate data = have ;                  
  class anatomic_site ;                      
  table anatomic_site="" * N="" ;            
run ;                                        

 If it's the latter, this dropping/renaming contortions may get you there:

option validvarname=any ;                                                                             
                                                                                                      
proc freq data = have noprint ;                                                                       
  tables anatomic_site / out = freq (drop=percent rename=(count="Anatomic Site"n anatomic_site=_fv)) ;
run ;                                                                                                 
proc transpose data = freq out = want (drop=_label_ rename=_name_="Freq Variable"n) ;                 
  id _fv ;                                                                                            
  var "anatomic site"n ;                                                                              
run ;                                                                                                 

Alternatively, instead of running TABULATE in case #1, you can run the above FREQ/TRANSPOSE combo and proc PRINT the data set WANT.

 

Kind regards

Paul D.

ChrisNZ
Tourmaline | Level 20

This gives you the crossings you want.

proc format ;
  value $site (multilabel)  'Urethral'
                            'Pharyngeal'
                            'Cervix'
                            'Rectum'       = [$10.]
                            'Urethral'
                            'Pharyngeal'   ='Urethral-Pharyngeal'
                            'Cervix' 
                            'Pharyngeal'   ='Cervix-Pharyngeal' ;
run;
proc means data = HAVE(keep=ANATOMIC_SITE) noprint nway;   
  class ANATOMIC_SITE / mlf; 
  output out=FREQ ;
  format ANATOMIC_SITE $site.;
run ; 

Use proc transpose if needed to rotate horizontally.

ANATOMIC_SITE _FREQ_
Cervix 2
Cervix-Pharyngeal 5
Rectum 3
Urethral 9

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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