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

Hi,

 

Could you help me figure out how to calculate percentage by firm and year?

 

My data looks like... 

 

data test;

input firm year director dummy;

datalines;

1001 2000 aaa 0

1001 2000 bbb 0

1001 2000 ccc 1

1001 2000 ddd 0

1001 2001 aaa 0

1001 2001 bbb 0 

1001 2001 ccc 1

1001 2001 ddd 0

1001 2001 eee 0

1002 2005 fff 1

1002 2005 ggg 1

1002 2005 hhh 0

1002 2005 iii 0

1002 2006 fff 1

1002 2006 ggg 0

1002 2006 hhh 1

1002 2006 iii 0

1002 2006 jjj 1

;

run;

 

I need to get a column (Percentage_MD) having the percentage of MD by firm and year.

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

And the percentage is calculated how? If it sum of 1 over count of all obs then just use PROC MEANS since the average of a binary variable is the same as the percent. 

 

proc means data=have mean;
by firm year;
var dummy;
run;

View solution in original post

5 REPLIES 5
Reeza
Super User

How is this column being calculated? You have no variable named MD? Percentage of what...

 


@hkim3677 wrote:

Hi,

 

Could you help me figure out how to calculate percentage by firm and year?

 

My data looks like... 

 

data test;

input firm year director dummy;

datalines;

1001 2000 aaa 0

1001 2000 bbb 0

1001 2000 ccc 1

1001 2000 ddd 0

1001 2001 aaa 0

1001 2001 bbb 0 

1001 2001 ccc 1

1001 2001 ddd 0

1001 2001 eee 0

1002 2005 fff 1

1002 2005 ggg 1

1002 2005 hhh 0

1002 2005 iii 0

1002 2006 fff 1

1002 2006 ggg 0

1002 2006 hhh 1

1002 2006 iii 0

1002 2006 jjj 1

;

run;

 

I need to get a column (Percentage_MD) having the percentage of MD by firm and year.

 

Thank you!


 

 

 

hkim3677
Calcite | Level 5

Oh sorry,

 

Dummy column is MD.

 

 

Reeza
Super User

And the percentage is calculated how? If it sum of 1 over count of all obs then just use PROC MEANS since the average of a binary variable is the same as the percent. 

 

proc means data=have mean;
by firm year;
var dummy;
run;
hkim3677
Calcite | Level 5

Sorry, I should have been clearer.

My question here is how to create the column containing the percentage of manager having MD=1 by firm and year.

 

Reeza
Super User

Then my previous answer was correct. 

 


@hkim3677 wrote:

Sorry, I should have been clearer.

My question here is how to create the column containing the percentage of manager having MD=1 by firm and year.

 


 

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