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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—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.