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!
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;
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;
This has worked like a dream - thank you!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.