BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Loobylou
Calcite | Level 5

I'm a relatively new SAS user, and looking for help to re-organise/summarise my data.

I have data on the gender of each Director in a series of firms, in the format:

 

FIRM ID          GENDER

1                           M

1                           M

1                           F

2                           M

2                           F

 

I want to be able to summarize and transpose this data, so I have only one observation per firm, and a count of how many male and female directors.  So the resulting format would look like: 

FIRM ID               MALE                 FEMALE

1                           2                         1

2                           1                         1

I'm wondering if I can use PROC TRANSPOSE for this, but can't figure out how to do this together with a count of male/female.   Grateful for any guidance/suggestions! 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
input FIRM_ID          GENDER $;
cards;
1                           M

1                           M

1                           F

2                           M

2                           F
;

proc sql;
create table want as
select FIRM_ID,sum(gender='M') as Male,sum(gender='F') as Female
from have
group by firm_id;
quit;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

data have;
input FIRM_ID          GENDER $;
cards;
1                           M

1                           M

1                           F

2                           M

2                           F
;

proc sql;
create table want as
select FIRM_ID,sum(gender='M') as Male,sum(gender='F') as Female
from have
group by firm_id;
quit;
Loobylou
Calcite | Level 5

This has worked like a dream - thank you!

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
  • 2 replies
  • 506 views
  • 0 likes
  • 2 in conversation