turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Proc Tabulate calculating percentages

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-13-2017 06:04 PM

I'm having problems using PROC TABULATE to calculate percentages.

Here is what my dataset looks like:

name | pass | month |

name1 | 0 | jan |

name1 | 1 | jan |

name2 | 1 | mar |

I can use proc freq to calculate the column percentages for each month, as follows:

proc freq data = test;

tables pass*month;

by name;

run;

Since I'm using the "BY" statement, it generates a separate table for each name. I'd like to use PROC TABULATE to have all the data in one table. Here is my proposed code, but it doesn't work.

proc tabulate data=test;

class name month;

table name*month*

(n='Total'*f=4.

ROWPCTN= 'Percentage of pass')

,

month/rts=60 box='Percentage of pass';

run;

What is wrong? It only calculates the total "N" but I want it to calculate "N" for each month, as in the proc freq column percentage.

thank you kindly.

Accepted Solutions

Solution

09-14-2017
12:33 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to sharonlee

09-13-2017 06:38 PM

With a 0/1 coded variable the sum = number of ones or pass (assuming 1 means pass), the mean will give you a percentage:

proc tabulate data=test; class name month; var pass; table name*month, pass=''*(sum='Number pass'*f=best5. mean='Percentage Pass'*f=percent8.1) ; run;

N for Pass would give you the number of tests administered that received a score.

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to sharonlee

09-13-2017 06:18 PM

Try adding it as a 'page'? You can also specify the levels by moving where the statistics are calculated using the ALL keyword.

```
table name, month*
(n='Total'*f=4.
ROWPCTN= 'Percentage of pass')
,
month/rts=60 box='Percentage of pass';
```

Solution

09-14-2017
12:33 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to sharonlee

09-13-2017 06:38 PM

With a 0/1 coded variable the sum = number of ones or pass (assuming 1 means pass), the mean will give you a percentage:

proc tabulate data=test; class name month; var pass; table name*month, pass=''*(sum='Number pass'*f=best5. mean='Percentage Pass'*f=percent8.1) ; run;

N for Pass would give you the number of tests administered that received a score.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ballardw

09-14-2017 12:33 PM

Beautiful! Works like a charm! Thanks!!!