I have a data set similar to this. I would like to get Alert case by anatomic site of inf.
| Alert Cases | Anatomic Site |
| Alert 1 | Urethral |
| Alertr 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 |
The output I want is something like this
| Urethra | Pharyngeal | Phryngeal & Urethra | Cervix | Cervix &Pharyngeal | Recturm& Urethra | |
| Alert Cases | 50 | 20 | 2 | 5 | 4 |
@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:
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.
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 |
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.