I have a data alike this
ID | AlertType | Gender | MSM | Gender_Sp | Race | Ethnicity | Number of partners | Age | GCHX | SXPharyngeal | Discharge | Dysuria | SXAbdomen |
1 | Alert | m | Yes | male | White | hispanic | 1 | 12 | yes | yes | no | no | no |
2 | Non-Alert | f | no | female | Black | non hispanic | 5 | 45 | no | no | yes | yes | yes |
3 | Seed | m | Unk | Unknown | other | hispanic | 3 | 23 | no | no | no | no | no |
4 | alert | f | no | female | Black | non hispanic | 4 | 36 | yes | yes | no | no | no |
5 | seed | mtf | Unk | Unknown | other | hispanic | 5 | 25 | no | no | yes | yes | yes |
6 | Seed | m | Yes | male | White | non hispanic | 6 | 21 | no | yes | no | no | no |
7 | Alert | m | no | female | Black | hispanic | 1 | 24 | no | no | no | no | no |
8 | Non-Alert | ftm | no | male | other | non hispanic | 2 | 27 | yes | no | yes | yes | yes |
9 | Seed | f | Unk | male | White | hispanic | -2 | 28 | no | yes | no | no | no |
10 | Non-Alert | m | no | female | Black | non hispanic | -4 | 23 | yes | no | no | no | no |
11 | Seed | f | Unk | Unknown | other | hispanic | -6 | 21 | no | yes | yes | yes | yes |
I would like to have a output table like this:
Alert | Non-Alert | Seed | |||||||
Male | Female | MSM | Male | Female | MSM | Male | Female | MSM | |
Gender | |||||||||
Race | |||||||||
Ethnicity | |||||||||
Number of Partners | |||||||||
Gender_sp | |||||||||
GCHX | |||||||||
SXPharyngeal | |||||||||
Discharge | |||||||||
Dysuria | |||||||||
SXAbdomen |
What is the best way to accomplish this in an efficient way?
I greatly appreciate your help.
Hi @Dhana18 ,
I believe you want to create a report rather than a SAS dataset as you want to display Gender and MSM categories by Alertype as columns.
May be you could try Proc Tabulate as shown below. In the Tables statement, you can specify the structure of your report to display statistics: (rows), (columns) * (statistics eg: n to show frequency)
proc tabulate data=have out=want;
class AlertType Gender MSM Gender_Sp Race Ethnicity Num_partners Age GCHX SXPharyngeal Discharge Dysuria SXAbdomen;
tables (Gender_Sp Race Ethnicity Num_partners Age GCHX SXPharyngeal Discharge Dysuria SXAbdomen),(AlertType *(Gender MSM))*n;
run;
NB: it seems that you have some data management to perform. For example, Alerttype contains "Alert" and "alert" -> proc tabulate is case-sensitive to identify modalities. So I think you can use a proc format for example to avoid these issues and group similar modalities. Or even to overwrite original data if it is allowed.
Hope this help.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.