BookmarkSubscribeRSS Feed
apaez062
Fluorite | Level 6

Hi there,

 

You ladies and gents have been really helpful in the past, so I'm hoping you may have an answer to this riddle we have with my colleagues.

 

We have a dataset that uses survey weights to arrive at the total population.

We want to calculate means and median income, for example, but before we do that, our target population needs to be EVENLY redistributed WITH weights NOT pre-weights - so that we may arrive at a total population that makes sense.

 

So, for example,

 

VAR1

1='Happy'

2='Sad'

3='Content'

4='None of the Above'

 

if I want to redistribute the 'Content' people evenly between the happy and sad people so as to end up with just 3 categories.

VAR2

1= Happy+1/2 Content

2= Sad +1/2 Content

3= None of the above

 

and then calculate the mean income, let's say, on the weighted population of happys and sads, we can't think of any way to do this.

 

Using RANUNI we could randomly redistribute the contents- but it  needs to be an exact even redistribution so 50-50 split of VAR1=3.

And it needs to split the WEIGHTED records not the unweighted ones.

 

The method we arrived at is below, but this will only split the unweighted records. The problem comes when you apply the weights to the redistributed variable and you find out that, obviously, since the weights can't be evenly redistributed then you end up with an uneven weighted count for VAR2=1 v. VAR2=2. where one group would constitute, let's say 55% and the other 45%.  

 

Proc sort data=work.ALO2016V1;

by VAR1;

run;

 

data work.ALO2016V2 (Drop=VAR_ID);

     set work.ALO2016V1;

 

/* the identification variable */

if VAR1 = 3 then do;

           VAR_id + 1;

                by VAR1;

                     if first.VAR1 then VAR_id = 1;

                     if last.VAR1 then VAR_id = 0;

                end;

 

 

/* redistribute */

if VAR1 = 1 and VAR_id = 0 then VAR2 = 1;                                

else if VAR1 = 2 and VAR_id = 0 then VAR2 = 2;                           

else if VAR1 = 3 and VAR_id in(1:50000) then VAR2 = 1;              

else if VAR1 = 3 and VAR_id in(50001:100000,0) then VAR2 = 2;

else if VAR1 = 4 and VAR_id = 0 then VAR2 = 3;                           

else VAR2 = 99;

 

run;

 

In short, is there a way to evenly redistribute the weighted records and then compute all other descriptive statistics based on those counts?

 

-Thank you so much!

 

 

 

 

 

 

 

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

I would sort the 'Content' observations by INCOME, and then affect the even-numbered rows to HAPPY and the odd-numbered rows to SAD.

If I understood your question properly.

Satish_Parida
Lapis Lazuli | Level 10

Please find the code.

 

data have;
input var1 $20.;
cards;
Happy
Sad
Content
None of the Above
Happy
Sad
Content
None of the Above
Happy
Sad
Content
None of the Above
Happy
Sad
Content
None of the Above
Happy
Sad
Content
None of the Above
Happy
Sad
Content
None of the Above
Content
Content
Content
Content
Content
Content
;
run;

data have;
set have;
rand_ord=RANUNI(8);
if var1='Happy' then var1f=1;
if var1='Sad' then var1f=2;
if var1='Content' then var1f=3;
if var1='None of the Above' then var1f=4;
run;

proc sort data=have;
by var1f rand_ord;
run;

data want(drop=var1f1 var1f2);
set have;
if var1f=3 then do;
	if var1f1 ge var1f2 then do; 
		var1nf=2;
		var1f2+1;
	end;
	else do;
		var1nf=1;
		var1f1+1;
	end;
	output;
end;
else do;
	var1nf=var1f;
	output;
end;
run;

 

Please let us know if it worked for you.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 570 views
  • 0 likes
  • 3 in conversation