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

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

 

Here is what my dataset looks like:

 

namepassmonth
name10jan
name11jan
name21mar

 

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

3 REPLIES 3
Reeza
Super User

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';
ballardw
Super User

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.

 

sharonlee
Quartz | Level 8

Beautiful! Works like a charm! Thanks!!!

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
  • 3 replies
  • 755 views
  • 3 likes
  • 3 in conversation