<?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: Calculating percentile for a variable but based on another variable? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-percentile-for-a-variable-but-based-on-another/m-p/680132#M79447</link>
    <description>You are correct.&lt;BR /&gt;&lt;BR /&gt;My solution was to separate the "rich" group into a separate table, then using left join in proc sql and using count(b.name) to find the number of people that meet the condition that a.poor ge b.rich , grouping by gender.&lt;BR /&gt;&lt;BR /&gt;This gave me the number of people 'rich' below each 'poor', by gender, and then I manually computed a percentile by dividing by the total number of rich.&lt;BR /&gt;&lt;BR /&gt;Seemed like the easiest way to go about it.</description>
    <pubDate>Fri, 28 Aug 2020 22:02:47 GMT</pubDate>
    <dc:creator>UniversitySas</dc:creator>
    <dc:date>2020-08-28T22:02:47Z</dc:date>
    <item>
      <title>Calculating percentile for a variable but based on another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-percentile-for-a-variable-but-based-on-another/m-p/679667#M79441</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if it is possible to calculate percentiles of a variable, not for itself, but relative to the values of another variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider the data below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data neighborhood_money;
   input Name $ 1-7 Gender $ 9 Poor 11-14 Rich 16-19;
   datalines;
Andrea  F 28.6 .
Carole  F 24.0 24.0
Clayton M 27.0 .
Curtis  M 22.6 22.6
Doug    M 27.3 27.3
Ellen   F 27.0 27.0
Jan     F 31.2 31.2
Jimmy   M 22.4 22.5
Karin   F 34.6 .
Mick    M 29.0 .
Richard M 29.7 .
Sam     M 27.2 .
Susan   F 35.1 .
;

proc sort data=neighborhood_money out=pairs;
   by gender;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If I use proc rank as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=pairs out=rankpair PERCENT;
   by gender;
   var poor rich;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I will get percentile values, by gender, for "poor" and "rich". However, the percentile value for "poor" is based on other "poor" values, and similarly for "rich" percentiles.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there instead a way, that I can get percentile values for "poor" relative to the values of "rich"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What I want&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;So for Andrea, who has&amp;nbsp; Poor = 28.6, when calculating the percentile, I only want to consider how Andrea's value of 28.6 is ranked against the other entries in the "Rich" column, for gender = F.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So Andrea's percentile for poor= 28.6 is calculated by looking at: Carole = 24.0 , Ellen = 27.0, and Jan = 31.2, as these women have values for the "Rich" column.&lt;/P&gt;&lt;P&gt;But she is not compared to the other two females, Karin = 34.6 (poor) and Susan = 35.1 (poor) or any of the men.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this possible to do? Calculate ranks based on other variables?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 10:52:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-percentile-for-a-variable-but-based-on-another/m-p/679667#M79441</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2020-08-27T10:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentile for a variable but based on another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-percentile-for-a-variable-but-based-on-another/m-p/679752#M79442</link>
      <description>&lt;P&gt;And for your example of Andrea what is the resulting "percentile" you expect?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you should provide an example of what you expect the output data set or report to look like.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 15:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-percentile-for-a-variable-but-based-on-another/m-p/679752#M79442</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-27T15:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentile for a variable but based on another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-percentile-for-a-variable-but-based-on-another/m-p/679797#M79443</link>
      <description>&lt;P&gt;Im not at my computer right now, so i can update the output i want when I get home.&lt;BR /&gt;&lt;BR /&gt;If we are ranking Andrea's value of 28.6 against the values: 24.0, 27.0, and 31.2, Andrea's percentile rank should = ~67 (66.666*), given that 2/3 of the sample are smaller than 28.6.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 23:04:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-percentile-for-a-variable-but-based-on-another/m-p/679797#M79443</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2020-08-27T23:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentile for a variable but based on another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-percentile-for-a-variable-but-based-on-another/m-p/680100#M79446</link>
      <description>&lt;P&gt;Let me see if I understand this. Since you are doing a BY-group analysis, you only need to look at one gender at a time. Let's look at females:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data F;
   input Name $ 1-7 Gender $ 9 Poor 11-14 Rich 16-19;
   datalines;
Andrea  F 28.6 .
Carole  F 24.0 24.0
Ellen   F 27.0 27.0
Jan     F 31.2 31.2
Karin   F 34.6 .
Susan   F 35.1 .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you want to compute the rank of the 'Poor' score with respect to the nonmissing 'Rich'&amp;nbsp; scores.&lt;/P&gt;
&lt;P&gt;The Rich scores are always {24, 27, 31.2}. So you want&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Andrea: 28.6 is what percentile in&amp;nbsp;{24, 27, 28.6, 31.2}&lt;/P&gt;
&lt;P&gt;Carol: 24 is what percentile in&amp;nbsp;{24, 27, 31.2}. (OR do we use&amp;nbsp;{24, 24, 27, 31.2} ?)&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;Susan: 35.1 is what percentile in&amp;nbsp;{24, 27, 31.2, 35.1}.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The short answer is that I do not think this is a computation built into any SAS procedure. I think you will have to program it yourself in the DATA step or PROC IML (much easier in IML).&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 20:26:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-percentile-for-a-variable-but-based-on-another/m-p/680100#M79446</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-08-28T20:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentile for a variable but based on another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-percentile-for-a-variable-but-based-on-another/m-p/680132#M79447</link>
      <description>You are correct.&lt;BR /&gt;&lt;BR /&gt;My solution was to separate the "rich" group into a separate table, then using left join in proc sql and using count(b.name) to find the number of people that meet the condition that a.poor ge b.rich , grouping by gender.&lt;BR /&gt;&lt;BR /&gt;This gave me the number of people 'rich' below each 'poor', by gender, and then I manually computed a percentile by dividing by the total number of rich.&lt;BR /&gt;&lt;BR /&gt;Seemed like the easiest way to go about it.</description>
      <pubDate>Fri, 28 Aug 2020 22:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-percentile-for-a-variable-but-based-on-another/m-p/680132#M79447</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2020-08-28T22:02:47Z</dc:date>
    </item>
  </channel>
</rss>

