BookmarkSubscribeRSS Feed
techsassy
Obsidian | Level 7

Hey folks, first time posting here. I'm running into trouble when trying to get a Percent N (PCTN) from a proc tabulate. We're trying to see how male/female college course enrollments and withdrawals differ, across several years. The following image shows 3 CSCI course, with female and male enrollment counts in the first column:

 

pctn.png

 

I want PCTN to reflect the INTRA-course, INTRA-year enrollment totals (i.e. the denominator should be the enrollment total for that course, in that year). So, for year 2013 and CSCI course 181, the F enrollment count of 68 should give a PCTN of 51.1%. Can someone help me modify my code to produce this result? Here's my code ('ay' is academic year, btw):

 

proc tabulate data= csci_grades missing;
     where ay in ('2013','2014') and sex in ('M','F');
     class course sex ay;
     var enroll withdraw_flag;
     table course=' '*(sex=' ' all='Course Total'), ay*(enroll*n enroll*pctn withdraw_flag*n withdraw_flag*pctn all='Inner All') all='Outer All';
run;

 

Thanks so much for your help!! 🙂

3 REPLIES 3
ballardw
Super User

If you provide some example data in the form of data step code we can test things a tad better.

 

It looks like you want a form of COLPCTN<enroll>

Cynthia_sas
SAS Super FREQ

Hi:

  Here is a sample program that illustrates the use of PCTN, ROWPCTN and COLPCTN and then shows calculating a percent of a group based on using a custom denominator. The program makes some fake data that sort of mimics what you are doing with nested groups in the row dimension and a date-based variable in the column dimension. You can see the same values for the rows and columns in every table, but the percent numbers change on the denominator being used.

 

cynthia

 

Here's an example of TABLE 1 (percent of Grand Total) versus TABLE 4 (custom denominator) since the program is so long, I am not going to post all 4 tables, but you should be able to run the program yourself to see the other tables.

 

TABLE 1

table1.png

TABLE 4

table4.png


proc tabulate data=newprice;
  class regionname productname date;
     var sale ;
     table regionname=' '*(productname=' ' all='Course Total') all,
           date*(sale*(n pctn)) all='Outer All'*(n pctn) /
           box='1 divided by grand total';
     table regionname=' '*(productname=' ' all='Course Total') all,
           date*(sale*(n rowpctn)) all='Outer All'*(n rowpctn) /
           box='2 divided by row total'; 
     table regionname=' '*(productname=' ' all='Course Total') all,
           date*(sale*(n colpctn)) all='Outer All'*(n colpctn) /
           box='3 divided by column total';
     table regionname=' '*(productname=' ' all='Course Total'),
           date*(sale*(n pctn<productname all>)) all='Outer All'*(n pctn<productname all>) /
           box='4 using custom denom to get productname total';
     format date monname3.;
run;

XiaoGuaiShou
Obsidian | Level 7
Thanks.Your 4th table is exactly what i need and i had trouble before.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2998 views
  • 3 likes
  • 4 in conversation