<?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: Using PROC RANK for Groups of the Same Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641400#M191149</link>
    <description>&lt;P&gt;please try the below code without the proc rank&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Variable1	Variable2	;
cards;
10 100 
20 100 
20 200 
30 100 
;

proc sort data=have;
by Variable1 Variable2;
run;

data want;
set have;
by Variable2 notsorted;
retain rank;
if first.Variable2 then rank=1;
else rank+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 20 Apr 2020 16:19:53 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2020-04-20T16:19:53Z</dc:date>
    <item>
      <title>Using PROC RANK for Groups of the Same Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641396#M191146</link>
      <description>&lt;P&gt;Today's hurdle:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 variables that are numeric.&amp;nbsp; The first variable can have duplicates, the second will not.&amp;nbsp; I am trying to use the PROC RANK function to assign a rank based on variable.&amp;nbsp; What I have found so far is how to rank all the observations.&amp;nbsp; This is the reference I have been working with: &lt;A href="https://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=n18s1uw2tqvtxdn1chay1qq1jke6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;HERE.&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my example and the desired outcome for "New Rank" where the "New Rank" is in descending order:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Variable 1&lt;/TD&gt;&lt;TD&gt;Variable 2&lt;/TD&gt;&lt;TD&gt;New Rank&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I feel like this should be another simple one but I can't get my head wrapped around it.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 16:07:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641396#M191146</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-04-20T16:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC RANK for Groups of the Same Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641400#M191149</link>
      <description>&lt;P&gt;please try the below code without the proc rank&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Variable1	Variable2	;
cards;
10 100 
20 100 
20 200 
30 100 
;

proc sort data=have;
by Variable1 Variable2;
run;

data want;
set have;
by Variable2 notsorted;
retain rank;
if first.Variable2 then rank=1;
else rank+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Apr 2020 16:19:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641400#M191149</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-04-20T16:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC RANK for Groups of the Same Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641404#M191152</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Variable1	Variable2;*	NewRank;
cards;
10	100	1
20	100	2
20	200	1
30	100	1
;
proc rank data=have out=want descending ties=dense;
by variable1;
   var variable2;
   ranks newrank;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Apr 2020 16:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641404#M191152</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-04-20T16:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC RANK for Groups of the Same Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641412#M191159</link>
      <description>&lt;P&gt;Here is my actual code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dwacq.data_sale;
	set dwacq.data_sale;
	by sale_loan_number_num notsorted;
	retain rank;
	if first.sale_loan_number then rank=1;
	else rank+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here are the results I want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;sale_loan_key&lt;/TD&gt;&lt;TD&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;sale_loan_number&lt;/TD&gt;&lt;TD&gt;New Rank&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the results I am getting with your code (and all the code I was trying before I posted the question):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;sale_loan_key&lt;/TD&gt;&lt;TD&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;sale_loan_number&lt;/TD&gt;&lt;TD&gt;New Rank&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 16:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641412#M191159</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-04-20T16:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC RANK for Groups of the Same Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641413#M191160</link>
      <description>&lt;P&gt;New Rank is not currently a variable in the dataset.&amp;nbsp; This is the new variable I want to create with the new rank based on var 1 and var2.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 16:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641413#M191160</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-04-20T16:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC RANK for Groups of the Same Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641414#M191161</link>
      <description>&lt;P&gt;Reverse the sort, numerate and then resort. Simplest to code option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by var1 descending var2;
run;

data want;
set have;
by var1 descending var2;
if first.var1 then count=1;
else count+1;
run;

proc sort data=want;
by var2 var2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24237"&gt;@elwayfan446&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Today's hurdle:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 2 variables that are numeric.&amp;nbsp; The first variable can have duplicates, the second will not.&amp;nbsp; I am trying to use the PROC RANK function to assign a rank based on variable.&amp;nbsp; What I have found so far is how to rank all the observations.&amp;nbsp; This is the reference I have been working with: &lt;A href="https://documentation.sas.com/?docsetId=proc&amp;amp;docsetTarget=n18s1uw2tqvtxdn1chay1qq1jke6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;HERE.&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my example and the desired outcome for "New Rank" where the "New Rank" is in descending order:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;Variable 1&lt;/TD&gt;
&lt;TD&gt;Variable 2&lt;/TD&gt;
&lt;TD&gt;New Rank&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;200&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;30&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel like this should be another simple one but I can't get my head wrapped around it.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 16:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641414#M191161</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-04-20T16:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC RANK for Groups of the Same Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641419#M191164</link>
      <description>&lt;P&gt;Yes you are right, albeit you perhaps missed to notice the newrank being commented in the input statement ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input Variable1	Variable2;*	NewRank;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 17:07:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641419#M191164</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-04-20T17:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using PROC RANK for Groups of the Same Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641425#M191167</link>
      <description>&lt;P&gt;This worked well and I always like as little code as possible! Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; and thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt; for your help as well!&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 17:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-PROC-RANK-for-Groups-of-the-Same-Variable/m-p/641425#M191167</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-04-20T17:23:31Z</dc:date>
    </item>
  </channel>
</rss>

