So, let's say I have a list of student enrollments by class.
Each observation lists the student id (ID), their credits attempted (SCH), and their class (class_id). Through proc tabulate, how do I tabulate the total number of hours (instead of counts) for each course for all students? I've already tried by changing the VAR statement to var SCH; but that still delivers counts. Is there a way to change that to deliver the SUM of the SCH instead of the count...
@eer_seer wrote:
Ok, great. Now, where do I apply this? I keep getting errors for the var statement?
When you get an error best practice on the forum is to copy the data step or procedure code along with all messages, notes, warnings and errors from the log, and paste the copied text into a code box opened on the forum with the </> icon. The code box is important to preserve the formatting of the text and any diagnostics that SAS provides in the log. The main message windows on this forum will reformat pasted text making the information less useful.
VAR variables in Proc Tabulate must be numeric.
27 proc tabulate data=ir.class_enrollment_improved missing; 28 title1 'Enrollment In Specific Courses for ALL Enrolled Engineering Students - Fall 2020'; 29 class strm sch class_subject_cd class_subject_ldesc class_acad_org_improved CLASS_ACAD_CAREER ; 30 var enrl_units_billing*sum*f=12.; _ 22 200 ERROR 22-322: Syntax error, expecting one of the following: a name, ;, -, /, :, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_. ERROR 200-322: The symbol is not recognized and will be ignored. 31 table class_acad_org_improved = 'Department Offering Class'*class_subject_cd = 'Class Subj. Code'*class_subject_ldesc = 31 ! 'Subject' all, strm; run; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE TABULATE used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
While the sum operator is to be applied to the analysis variable, it is not meant to be in the VAR statement listing the analysis variables. It should be in the TABLE statement, as in:
proc tabulate data=ir.class_enrollment_improved missing;
title1 'Enrollment In Specific Courses for ALL Enrolled Engineering Students - Fall 2020';
class strm sch class_subject_cd class_subject_ldesc class_acad_org_improved CLASS_ACAD_CAREER ;
var enrl_units_billing;
table class_acad_org_improved = 'Department Offering Class'
* class_subject_cd = 'Class Subj. Code'
* class_subject_ldesc =' Subject'
all
, strm *var enrl_units_billing*sum*f=12.;
run;
@eer_seer wrote:
27 proc tabulate data=ir.class_enrollment_improved missing; 28 title1 'Enrollment In Specific Courses for ALL Enrolled Engineering Students - Fall 2020'; 29 class strm sch class_subject_cd class_subject_ldesc class_acad_org_improved CLASS_ACAD_CAREER ; 30 var enrl_units_billing*sum*f=12.; _ 22 200 ERROR 22-322: Syntax error, expecting one of the following: a name, ;, -, /, :, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_. ERROR 200-322: The symbol is not recognized and will be ignored. 31 table class_acad_org_improved = 'Department Offering Class'*class_subject_cd = 'Class Subj. Code'*class_subject_ldesc = 31 ! 'Subject' all, strm; run; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE TABULATE used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
Var statement in Proc Tabulate is intended to 1) list numeric variables and 2) apply some options, basically either appearance options such as text appearance or the weight option to specify a weight. No statistics (body of a Table statement), no formats (body of Table statement), no Labels (Label statement or body of Table).
When in doubt check the documentation.
The third example has an example of what you're trying to do.
proc tabulate data=energy format=comma12.;
class region division type;
var expenditures;
table region*(division all='Subtotal')
all='Total for All Regions'*f=dollar12.,
type='Customer Base'*expenditures=' '*sum=' '
all='All Customers'*expenditures=' '*sum=' '
/ rts=25;
format region regfmt. division divfmt. type usetype.;
title 'Energy Expenditures for Each Region';
title2 '(millions of dollars)';
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.