BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

I have a data alike this 

IDAlertTypeGenderMSMGender_SpRaceEthnicityNumber of partners Age GCHXSXPharyngealDischarge Dysuria SXAbdomen
1AlertmYesmaleWhite hispanic112yes yes no no no 
2Non-Alert fnofemaleBlack non hispanic545no no yes yes yes 
3SeedmUnkUnknownotherhispanic323no no no no no 
4alertfnofemaleBlack non hispanic436yes yes no no no 
5seedmtfUnkUnknownotherhispanic525no no yes yes yes 
6SeedmYesmaleWhite non hispanic621no yes no no no 
7AlertmnofemaleBlack hispanic124no no no no no 
8Non-Alert ftmnomaleothernon hispanic227yes no yes yes yes 
9SeedfUnkmaleWhite hispanic-228no yes no no no 
10Non-Alert mnofemaleBlack non hispanic-423yes no no no no 
11SeedfUnkUnknownotherhispanic-621no yes yes yes yes 

 

I would like to have a output table like this:

 AlertNon-AlertSeed
 MaleFemaleMSMMaleFemaleMSMMaleFemaleMSM
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.

1 REPLY 1
ed_sas_member
Meteorite | Level 14

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.

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 603 views
  • 0 likes
  • 2 in conversation