<?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: Double sorting Portfolios into Quintiles in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Double-sorting-Portfolios-into-Quintiles/m-p/453400#M114568</link>
    <description>&lt;P&gt;I am not sure whether is is correct. Can you tell me the correct code then? The idea of the first step is to sort monthly on var1.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Apr 2018 22:48:22 GMT</pubDate>
    <dc:creator>Agent1592</dc:creator>
    <dc:date>2018-04-11T22:48:22Z</dc:date>
    <item>
      <title>Double sorting Portfolios into Quintiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-sorting-Portfolios-into-Quintiles/m-p/453391#M114564</link>
      <description>&lt;P&gt;Dear SAS Community. I am trying to double sort data into quintiles. First I am sorting monthly on var1. Then I am sorting within each group of var1, var2. Here is my current code. My issue is in the second step I am not sorting just&amp;nbsp;by&amp;nbsp;rvar1 but not by yymm. How can I sort by by rvar1 and yymm in the second step&amp;nbsp;&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;/*First Step- Sort data into quintiles based on var1*/&lt;BR /&gt;proc sort data=have;
      by yymm;
run;
proc rank data=have out=have groups=5;
	by yymm;
	var var1;
	ranks rvar1 ;
	run;&lt;BR /&gt;/*Second Step- sort var2 within each quintile of var1 but by yymm&lt;BR /&gt;The idea is to avoid look ahead bias*/&lt;BR /&gt;
proc sort data=have;
      by rvar1;
run;
proc rank data=have out=have groups=5;
	by rvar1;
	var var2;
	ranks rvar2 ;
	run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 22:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-sorting-Portfolios-into-Quintiles/m-p/453391#M114564</guid>
      <dc:creator>Agent1592</dc:creator>
      <dc:date>2018-04-11T22:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: Double sorting Portfolios into Quintiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-sorting-Portfolios-into-Quintiles/m-p/453399#M114567</link>
      <description>&lt;P&gt;Are you sure those first steps are doing what you expect? Based on your comments, that doesn't seem correct...&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 22:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-sorting-Portfolios-into-Quintiles/m-p/453399#M114567</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-11T22:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: Double sorting Portfolios into Quintiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-sorting-Portfolios-into-Quintiles/m-p/453400#M114568</link>
      <description>&lt;P&gt;I am not sure whether is is correct. Can you tell me the correct code then? The idea of the first step is to sort monthly on var1.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 22:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-sorting-Portfolios-into-Quintiles/m-p/453400#M114568</guid>
      <dc:creator>Agent1592</dc:creator>
      <dc:date>2018-04-11T22:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Double sorting Portfolios into Quintiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-sorting-Portfolios-into-Quintiles/m-p/453405#M114570</link>
      <description>&lt;P&gt;It's not a matter of code, it's a matter of logic. Your code is syntax wise correct, but I'm not sure if you're stating your logic correctly because the logic doesn't match the code shown...and I can't know which is incorrect because there's no context and it's not my problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, you say your first step is to sort by VAR1 but in the BY statement in your first sort, it's by YYMM.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*First Step- Sort data into quintiles based on var1*/
proc sort data=have;
      by yymm;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you know what you're trying to do, I would open my data set after the sort and see if it was sorted correctly and the ranks are created accordingly. There isn't anything too difficult in this question so you should be able to guess and test it - it is the scientific way after all &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 22:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-sorting-Portfolios-into-Quintiles/m-p/453405#M114570</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-11T22:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Double sorting Portfolios into Quintiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-sorting-Portfolios-into-Quintiles/m-p/453407#M114571</link>
      <description>&lt;P&gt;If I have a clue as to what you want one of these might be what you are looking for:&lt;/P&gt;
&lt;PRE&gt;proc sort data=have;
      by yymm rvar1;
run;
proc rank data=have out=have2 groups=5;
	by yymm rvar1;
	var var2;
	ranks rvar2 ;
run;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sort data=have;
      by rvar1 yymm;
run;
proc rank data=have2 out=have groups=5;
	by rvar1 yymm;
	var var2;
	ranks rvar2 ;
run;&lt;/PRE&gt;
&lt;P&gt;if not then time to post some input data and what the result for that data would be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 22:58:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-sorting-Portfolios-into-Quintiles/m-p/453407#M114571</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-11T22:58:08Z</dc:date>
    </item>
  </channel>
</rss>

