DATA Step, Macro, Functions and more

Weight Categorical Variables in Proc Tabulate

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

Weight Categorical Variables in Proc Tabulate

Hi all,

 

I am running the below code, attempting to create a table using Proc Tabulate. I am using categorical variables and am attempting to weight observations using the variable "discwt". However, I can't get the weighting to work. Regardless of what I do, my code only produces an unweighted table. 

 

I am running this on SAS 9.4 TS 1M1.

 

Thanks!

 

proc tabulate data = work.redo_t1;
	title 'Table 1a';
	class cat_flag race ; 
	table race, (cat_flag)*(N colpctn);
	var discwt / weight = discwt;
	weight discwt;
run;

Accepted Solutions
Solution
‎09-03-2017 02:14 PM
PROC Star
Posts: 7,480

Re: Weight Categorical Variables in Proc Tabulate

You want to use the FREQ option .. NOT the WEIGHT option. e.g.:

data redo_t1;
	input ID discwt cat_flag race;
	datalines; 
		01 5 1 1
		02 5 1 2
		03 5 1 1
		04 5 1 2
		05 5 1 1
		06 5 3 2
		07 5 3 1
		08 5 3 2
		09 5 3 1
		10 5 3 2
	;
run;

proc tabulate data = work.redo_t1;
	title 'Table 1a';
	class cat_flag race ; 
	table race, (cat_flag)*(N colpctn);
	var discwt / weight = discwt;
	freq discwt;
run;

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Super User
Posts: 19,822

Re: Weight Categorical Variables in Proc Tabulate

Can you generate some data we can work with to replicate and test your issue? 

Occasional Contributor
Posts: 16

Re: Weight Categorical Variables in Proc Tabulate

Here is code to produce sample data:

 

data redo_t1;
	input ID discwt cat_flag race;
	datalines; 
		01 5 1 1
		02 5 1 2
		03 5 1 1
		04 5 1 2
		05 5 1 1
		06 5 3 2
		07 5 3 1
		08 5 3 2
		09 5 3 1
		10 5 3 2
	;
run;

proc tabulate data = work.redo_t1;
	title 'Table 1a';
	class cat_flag race ; 
	table race, (cat_flag)*(N colpctn);
	var discwt / weight = discwt;
	weight discwt;
run;

and i'd like my table to look something like this:

 

                   Cat 1       Cat 3

Region 1     15           10

Region 3     10           15

 

and not 

                   Cat 1       Cat 3

Region 1     3             2

Region 3     2             3

Solution
‎09-03-2017 02:14 PM
PROC Star
Posts: 7,480

Re: Weight Categorical Variables in Proc Tabulate

You want to use the FREQ option .. NOT the WEIGHT option. e.g.:

data redo_t1;
	input ID discwt cat_flag race;
	datalines; 
		01 5 1 1
		02 5 1 2
		03 5 1 1
		04 5 1 2
		05 5 1 1
		06 5 3 2
		07 5 3 1
		08 5 3 2
		09 5 3 1
		10 5 3 2
	;
run;

proc tabulate data = work.redo_t1;
	title 'Table 1a';
	class cat_flag race ; 
	table race, (cat_flag)*(N colpctn);
	var discwt / weight = discwt;
	freq discwt;
run;

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 16

Re: Weight Categorical Variables in Proc Tabulate

Thank you for your help! This is exactly what I was looking for. I appreciate your effort and time.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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