<?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: how can I create a variable that indicates the percentile that each observation is in with weigh in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-can-I-create-a-variable-that-indicates-the-percentile-that/m-p/498273#M72517</link>
    <description>&lt;P&gt;The do loop&amp;nbsp;compares the value with the quartile boundaries, in sequence 1(P25) 2(P50) 3(P75), it goes to 4 and stops&amp;nbsp;if the value is greater than P75.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Sep 2018 03:03:21 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2018-09-24T03:03:21Z</dc:date>
    <item>
      <title>how can I create a variable that indicates the percentile that each observation is in with weights?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-can-I-create-a-variable-that-indicates-the-percentile-that/m-p/498090#M72496</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data with a scaling factor, I want to analyze the distribution of the values , so I create a variable that indicates the quartile of the observation. This is explained &lt;A href="http://support.sas.com/kb/22/759.html" target="_self"&gt;here&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; proc rank data=have groups=4 out=want;
      var var1 var2;
      ranks quartile_var1 quartile_var2;
   run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This code produces this, ignoring the scaling&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My issue is, that I have an unrepresentative sample with some oversampling of certain demographics,&amp;nbsp; but I have a scaling factor/ weight to adjust for this. So I'd like to calculate the quartiles while adjusting for the oversampling with my scaling factor.&lt;/P&gt;&lt;P&gt;How to get&amp;nbsp; this is explained &lt;A href="https://blogs.sas.com/content/iml/2016/08/29/weighted-percentiles.html" target="_self"&gt;here&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=have p25 p50 p75;
   weight wt;                     
   var var1 var2;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;of course I could first calculate the quartiles cutoff values and then use if statements to build the variable but the rank procedure is so elegant.&lt;/P&gt;&lt;P&gt;rank doesn't seem to support weight though.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;suggestions how to do this quickly with few lines of code are well appreciated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Sep 2018 16:36:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-can-I-create-a-variable-that-indicates-the-percentile-that/m-p/498090#M72496</guid>
      <dc:creator>asdf0990</dc:creator>
      <dc:date>2018-09-22T16:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: how can I create a variable that indicates the percentile that each observation is in with weigh</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-can-I-create-a-variable-that-indicates-the-percentile-that/m-p/498168#M72503</link>
      <description>&lt;P&gt;A few lines of code &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc univariate data=sashelp.heart noprint;
var ageAtStart height;
weight weight;
output out=quant p25=p_a25 p_h25 p50=p_a50 p_h50 p75=p_a75 p_h75;
run;

data heartQuant;
if _n_=1 then set quant;
array a p_a25 p_a50 p_a75;
array h p_h25 p_h50 p_h75;
set sashelp.heart;
if not missing(ageAtStart) then 
    do ageQuant = 1 to 3 until(ageAtStart &amp;lt; a{ageQuant}); end;
if not missing(height) then
    do heightQuant = 1 to 3 until(height &amp;lt; h{heightQuant}); end;
drop p_: ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Sep 2018 04:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-can-I-create-a-variable-that-indicates-the-percentile-that/m-p/498168#M72503</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-09-23T04:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: how can I create a variable that indicates the percentile that each observation is in with weigh</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-can-I-create-a-variable-that-indicates-the-percentile-that/m-p/498195#M72504</link>
      <description>&lt;P&gt;thank you, I have to do this for about 20 variables.&lt;/P&gt;&lt;P&gt;if I got your code&lt;/P&gt;&lt;P&gt;I have to add them to the second line and then have to greate an array for each variable&lt;/P&gt;&lt;P&gt;and each it's own do statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What does the do statement do?&lt;/P&gt;</description>
      <pubDate>Sun, 23 Sep 2018 09:26:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-can-I-create-a-variable-that-indicates-the-percentile-that/m-p/498195#M72504</guid>
      <dc:creator>asdf0990</dc:creator>
      <dc:date>2018-09-23T09:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: how can I create a variable that indicates the percentile that each observation is in with weigh</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-can-I-create-a-variable-that-indicates-the-percentile-that/m-p/498273#M72517</link>
      <description>&lt;P&gt;The do loop&amp;nbsp;compares the value with the quartile boundaries, in sequence 1(P25) 2(P50) 3(P75), it goes to 4 and stops&amp;nbsp;if the value is greater than P75.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 03:03:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-can-I-create-a-variable-that-indicates-the-percentile-that/m-p/498273#M72517</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-09-24T03:03:21Z</dc:date>
    </item>
  </channel>
</rss>

