<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Conditionally redistributing observations WITH survey weights applied in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-redistributing-observations-WITH-survey-weights/m-p/538166#M148129</link>
    <description>&lt;P&gt;Please find the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let us know if it worked for you.&lt;/P&gt;</description>
    <pubDate>Mon, 25 Feb 2019 02:43:34 GMT</pubDate>
    <dc:creator>Satish_Parida</dc:creator>
    <dc:date>2019-02-25T02:43:34Z</dc:date>
    <item>
      <title>Conditionally redistributing observations WITH survey weights applied</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-redistributing-observations-WITH-survey-weights/m-p/537730#M147931</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We have a dataset that uses survey weights to arrive at the total population.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, for example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VAR1&lt;/P&gt;&lt;P&gt;1='Happy'&lt;/P&gt;&lt;P&gt;2='Sad'&lt;/P&gt;&lt;P&gt;3='Content'&lt;/P&gt;&lt;P&gt;4='None of the Above'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if I want to redistribute the 'Content' people evenly between the happy and sad people&amp;nbsp;so as to end up with just 3 categories.&lt;/P&gt;&lt;P&gt;VAR2&lt;/P&gt;&lt;P&gt;1=&amp;nbsp;Happy+1/2 Content&lt;/P&gt;&lt;P&gt;2= Sad +1/2 Content&lt;/P&gt;&lt;P&gt;3= None of the above&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using RANUNI we could randomly redistribute the contents- but it&amp;nbsp; needs to be an exact even redistribution so 50-50 split of VAR1=3.&lt;/P&gt;&lt;P&gt;And it needs to split the WEIGHTED records not the unweighted ones.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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%. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc sort data=work.ALO2016V1;&lt;/P&gt;&lt;P&gt;by VAR1;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; work.ALO2016V2 (Drop=VAR_ID);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set work.ALO2016V1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* the identification variable */&lt;/P&gt;&lt;P&gt;if&amp;nbsp;VAR1 = &lt;STRONG&gt;3&lt;/STRONG&gt; then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VAR_id + &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by VAR1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.VAR1 then VAR_id = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if last.VAR1 then VAR_id = &lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* redistribute */&lt;/P&gt;&lt;P&gt;if&amp;nbsp;VAR1 = &lt;STRONG&gt;1&lt;/STRONG&gt; and VAR_id = &lt;STRONG&gt;0&lt;/STRONG&gt; then&amp;nbsp;VAR2 = &lt;STRONG&gt;1&lt;/STRONG&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;else if VAR1&amp;nbsp;= &lt;STRONG&gt;2&lt;/STRONG&gt; and VAR_id = &lt;STRONG&gt;0&lt;/STRONG&gt; then&amp;nbsp;VAR2 = &lt;STRONG&gt;2&lt;/STRONG&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;else if&amp;nbsp;VAR1 = &lt;STRONG&gt;3&lt;/STRONG&gt; and VAR_id in(&lt;STRONG&gt;1&lt;/STRONG&gt;:&lt;STRONG&gt;50000&lt;/STRONG&gt;) then&amp;nbsp;VAR2 = &lt;STRONG&gt;1&lt;/STRONG&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;else if&amp;nbsp;VAR1 = &lt;STRONG&gt;3&lt;/STRONG&gt; and VAR_id in(&lt;STRONG&gt;50001&lt;/STRONG&gt;:&lt;STRONG&gt;100000&lt;/STRONG&gt;,&lt;STRONG&gt;0&lt;/STRONG&gt;) then&amp;nbsp;VAR2 = &lt;STRONG&gt;2&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;else if VAR1 = &lt;STRONG&gt;4&lt;/STRONG&gt; and VAR_id = &lt;STRONG&gt;0&lt;/STRONG&gt; then VAR2&amp;nbsp;= &lt;STRONG&gt;3&lt;/STRONG&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;else VAR2 = &lt;STRONG&gt;99&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In short, is there a way to evenly redistribute the weighted records and then compute all other descriptive statistics based on those counts?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Thank you so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 15:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-redistributing-observations-WITH-survey-weights/m-p/537730#M147931</guid>
      <dc:creator>apaez062</dc:creator>
      <dc:date>2019-02-22T15:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally redistributing observations WITH survey weights applied</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-redistributing-observations-WITH-survey-weights/m-p/538126#M148112</link>
      <description>&lt;P&gt;I would sort the &lt;SPAN&gt;'Content'&amp;nbsp;&lt;/SPAN&gt;observations by INCOME, and then affect the even-numbered rows to HAPPY and the odd-numbered rows to SAD.&lt;/P&gt;
&lt;P&gt;If I understood your question properly.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Feb 2019 20:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-redistributing-observations-WITH-survey-weights/m-p/538126#M148112</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-02-24T20:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally redistributing observations WITH survey weights applied</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-redistributing-observations-WITH-survey-weights/m-p/538166#M148129</link>
      <description>&lt;P&gt;Please find the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let us know if it worked for you.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 02:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-redistributing-observations-WITH-survey-weights/m-p/538166#M148129</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2019-02-25T02:43:34Z</dc:date>
    </item>
  </channel>
</rss>

