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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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