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

I'm following the example in Weight the Results II in the book:

https://books.google.com/books?id=6lpACQAAQBAJ&pg=PT230&lpg=PT230&dq=tabulate+sumwgt&source=bl&ots=m...

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Try the FREQ option instead of Weight.

View solution in original post

10 REPLIES 10
Reeza
Super User

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;

DavidPhillips2
Rhodochrosite | Level 12

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;

Reeza
Super User

It does in 9.3 as well.

Sex should be a class variable as it's a grouping variable not an analysis variable.

DavidPhillips2
Rhodochrosite | Level 12

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.

DavidPhillips2
Rhodochrosite | Level 12

What I am trying to create is like this multiplied by the column admissions.

gender.png

DavidPhillips2
Rhodochrosite | Level 12

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;

Reeza
Super User

Can you post sample input data?

DavidPhillips2
Rhodochrosite | Level 12

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

;

Reeza
Super User

Try the FREQ option instead of Weight.

DavidPhillips2
Rhodochrosite | Level 12

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;

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
  • 10 replies
  • 1689 views
  • 0 likes
  • 2 in conversation