BookmarkSubscribeRSS Feed
Bedi
Calcite | Level 5

Hi

 

I am trying to generate weighted percentages by using the below codes but it generates un-weigted percentages.

My weight variable is discwt

 

 

data redo_t1;
	input ID discwt 3.1 cat_flag race;
	datalines; 
		01 0.2 1 1
		02 0.4 1 2
		03 0.4 1 1
		04 0.4 1 2
		05 0.4 1 1
		06 0.1 3 2
		07 1.2 3 1
		08 0.4 3 2
		09 1.0 3 1
		10 0.4 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;

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

I don't know what you are trying to do here, but you can't weight a variable by itself. That simply doesn't make any sense from a mathematical point of view. Please type in the desired output from this data set, and how the desired output is computed, and perhaps someone can generate code to produce the desired output.

--
Paige Miller
Reeza
Super User
data redo_t1;
	input ID discwt 3.1 cat_flag race;
    counter=1;
	datalines; 
		01 0.2 1 1
		02 0.4 1 2
		03 0.5 1 1
		04 0.4 1 2
		05 0.4 1 1
		06 0.1 3 2
		07 1.2 3 1
		08 0.4 3 2
		09 1.0 3 1
		10 0.4 3 2
	;
run;

title 'with weights';
proc tabulate data = work.redo_t1;
	title 'Table 1a';
	class cat_flag race ; 
    var counter;
    weight discwt;
	table race, (cat_flag)*counter*(sum colpctn);

run;
Bedi
Calcite | Level 5
Thanks for the revert.

I tried the code, it does gives me weighted count but the percentages from
'COLPCTN' are still unweighted.

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
  • 3 replies
  • 794 views
  • 0 likes
  • 3 in conversation