I'm following the example in Weight the Results II in the book:
and I’m running into the error
ERROR: Variable GENDER in list does not match type prescribed for this list.
when I uncomment the comment below. Does the line not work in SAS 9.2? Am I missing something simple?
I’m trying to multiply gender by the number of admissions.
proc tabulate data=enrollment out=barGraphDataTEST;
/*var gender / weight=admissions;*/
class academic_period_desc gender;
table academic_period_desc, gender*rowpctn gender*colpctn;
run;
Try the FREQ option instead of Weight.
It works as both char and numeric for me in SAS9.3
proc tabulate data=sashelp.class out=barGraphDataTEST;
/*var gender / weight=admissions;*/
class age sex;
table age, sex*rowpctn sex*colpctn;
run;
data class;
set sashelp.class;
gender=ifn(sex='F', 1, 0);
run;
proc tabulate data=class out=barGraphDataTEST;
/*var gender / weight=admissions;*/
class age gender;
table age, gender*rowpctn gender*colpctn;
run;
In 9.2 this breaks
proc tabulate data=sashelp.class out=barGraphDataTEST;
var sex / weight=age;
class age;
table age, sex*rowpctn sex*colpctn;
run;
It does in 9.3 as well.
Sex should be a class variable as it's a grouping variable not an analysis variable.
How can I multiply a grouping variable by a weight column? E.g. Sex by age and still use the rowpctn with it? The idea is if there are 15 instances of gender and the column age = 100. The value should be 1500.
What I am trying to create is like this multiplied by the column admissions.
This produces the same structure but oddly does not multiply by admissions. It simply adds the grouping admissions above gender.
proc tabulate data=enrollment out=barGraphDataTEST;
var admissions;
class academic_period_desc gender;
table academic_period_desc, gender*(admissions*rowpctn) gender*(admissions*colpctn);
run;
This produces the same thing. It doesn't actually weight.
proc tabulate data=enrollment out=barGraphDataTEST;
weight admissions;
class academic_period_desc gender;
table academic_period_desc, (gender*admissions)*rowpctn (gender*admissions)*colpctn;
run;
Can you post sample input data?
data genderData;
input gender $ 1-12 year admissions;
datalines;
Not Reported 2010 3
Not Reported 2011 5
Not Reported 2012 7
Not Reported 2013 6
Not Reported 2014 4
Male 2010 5
Male 2011 1
Male 2012 1
Male 2013 3
Male 2014 4
Female 2010 2
Female 2011 1
Female 2012 1
Female 2013 2
Female 2014 1
;
Try the FREQ option instead of Weight.
thanks
This worked.
data genderData;
input gender $ 1-12 year admissions;
datalines;
Not Reported 2010 3
Not Reported 2011 5
Not Reported 2012 7
Not Reported 2013 6
Not Reported 2014 4
Male 2010 5
Male 2011 1
Male 2012 1
Male 2013 3
Male 2014 4
Female 2010 2
Female 2011 1
Female 2012 1
Female 2013 2
Female 2014 1
;
proc tabulate data=genderData out=barGraphDataTEST;
freq admissions;
class year gender;
table year, (gender)*rowpctn (gender)*colpctn;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.