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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 517 views
  • 0 likes
  • 2 in conversation