<?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: Custom sort order based on a predefined sort order in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743014#M29218</link>
    <description>Sorry, correction in last paragraph: Now the sort order should be ORANGES, BANANAS, APRICOTS, APPLES.</description>
    <pubDate>Fri, 21 May 2021 18:47:27 GMT</pubDate>
    <dc:creator>sas-inquirer</dc:creator>
    <dc:date>2021-05-21T18:47:27Z</dc:date>
    <item>
      <title>Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/742942#M29213</link>
      <description>&lt;P&gt;Good morning SAS Gurus,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; I am having trouble ending up with a custom sort order in SAS 9.4. I have combined two datasets. The first dataset contained a custom sort order that needs to be maintained. The second dataset contained new observations that needed to be added to the first dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After combining the datasets, the table looks like this (where new obs have SORT_ORDER = .):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input SORT_ORDER KEY_VAR $;
CARDS;
1 1-2-9
2 1-2-4
4 1-2-5
5 1-2-8
. 1-1-5
. 1-2-7
. 1-3-1
. 1-3-3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I can't sort by SORT_ORER because the new observations will be out of order based on the KEY_VAR. I can't sort by the KEY_VAR because it will disrupt the original sort order. I want to end up with this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input SORT_ORDER KEY_VAR $;
CARDS;
. 1-1-5
1 1-2-9
2 1-2-4
4 1-2-5
. 1-2-7
5 1-2-8
. 1-3-1
. 1-3-3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If I was doing this manually, I would take each new observation and insert it based on the KEY_VAR numeric order.&lt;/P&gt;&lt;P&gt;Where the logic would be if SORT_ORDER = . then insert based on KEY_VAR.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this makes sense. Any suggestions would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 16:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/742942#M29213</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2021-05-21T16:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/742977#M29214</link>
      <description>&lt;P&gt;Missiing values make very poor controllers of order in general. So why is "missing" used for order?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may help to provide what the output of your example should actually look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And are there any other variables in your data that need to be considered? If so, how?.&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 17:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/742977#M29214</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-21T17:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743000#M29215</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/75160"&gt;@sas-inquirer&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many non-standard sort orders can be implemented using a suitable ORDER BY clause in a PROC SQL step. A fundamental (mathematical) prerequisite of&amp;nbsp;&lt;EM&gt;any&lt;/EM&gt;&amp;nbsp;of these sort orders is a definition satisfying the properties of a so called &lt;EM&gt;linear order&lt;/EM&gt; (cf. &lt;A href="https://en.wikipedia.org/wiki/Total_order" target="_blank" rel="noopener"&gt;https://en.wikipedia.org/wiki/Total_order&lt;/A&gt;). In particular, for any two different records to be sorted there must be no ambiguity as to which one takes precedence of the other. For example, you suggest&lt;/P&gt;
&lt;PRE&gt;SORT_ORDER KEY_VAR
.          1-2-7
5          1-2-8&lt;/PRE&gt;
&lt;P&gt;because you "&lt;SPAN&gt;insert" &lt;/SPAN&gt;the new records "&lt;SPAN&gt;based on KEY_VAR." But at the same time you want&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;SORT_ORDER KEY_VAR
1          1-2-9
.          1-2-7&lt;/PRE&gt;
&lt;P&gt;which seems to follow a different "logic."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide a rule that is applicable to any two (SORT_ORDER, KEY_VAR) pairs?&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 18:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743000#M29215</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-05-21T18:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743007#M29216</link>
      <description>Hi Ballardw&lt;BR /&gt;&lt;BR /&gt;You're right, missing values are very poor controllers. I've never had to deal with this type of issue before. Once I can figure out the sort order issue, I will redo the sort order variable so that each observation has a value.&lt;BR /&gt;&lt;BR /&gt;The output will be:&lt;BR /&gt;NEW_SORT_ORDER KEY_VAR&lt;BR /&gt;1 1-1-5&lt;BR /&gt;2 1-2-9&lt;BR /&gt;3 1-2-4&lt;BR /&gt;4 1-2-5&lt;BR /&gt;5 1-2-7&lt;BR /&gt;6 1-2-8&lt;BR /&gt;7 1-3-1&lt;BR /&gt;8 1-3-3&lt;BR /&gt;&lt;BR /&gt;No other variables need to be considered for the purpose of sorting. There are many other variables but they are directly associated with the KEY_VAR (i.e. first digit represents something, second something else etc.) The KEY_VAR is unique.&lt;BR /&gt;&lt;BR /&gt;The problem is that the original table represents a report that the user wants ordered in a specific way. My role is to update this report with some new KEY_VAR's but maintain any sort order that existed in the original report. The new KEY_VAR's are to be inserted based on their KEY_VAR numeric order without disrupting the original sort order.&lt;BR /&gt;&lt;BR /&gt;Perhaps some context may help. Let's say the report represents grocery items from a store and each item is assigned a unique KEY which represents the manufacturer, the country and the type of food. The new KEY_VARs are new items that the store is offering. Management is very interested in ORANGES and so is used to seeing the report with ORANGES (1-2-9) followed by BANANAS (1-2-4) followed by APPLES (1-2-8) and so a SORT_ORDER variable was created. Unfortunately, the KEY_VAR cannot be changed. The store now offers APRICOTS and has assigned the key (1-2-7). Now the sort order should be ORANGES, BANANAS, APPLES, APRICOTS so the sort is giving priority to the SORT_ORDER first and then the KEY_VAR if cases where the item is new.&lt;BR /&gt;</description>
      <pubDate>Fri, 21 May 2021 18:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743007#M29216</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2021-05-21T18:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743010#M29217</link>
      <description>The rule is SORT_ORDER takes precedence over KEY_VAR.</description>
      <pubDate>Fri, 21 May 2021 18:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743010#M29217</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2021-05-21T18:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743014#M29218</link>
      <description>Sorry, correction in last paragraph: Now the sort order should be ORANGES, BANANAS, APRICOTS, APPLES.</description>
      <pubDate>Fri, 21 May 2021 18:47:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743014#M29218</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2021-05-21T18:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743023#M29219</link>
      <description>&lt;P&gt;Still don't know what the desired output should look like.&lt;/P&gt;
&lt;P&gt;You mentioned a "report".&lt;/P&gt;
&lt;P&gt;If your report is generated with Proc Report or Tabulate it might be possible that PRELOADFMT can control appearance.&lt;/P&gt;
&lt;P&gt;The steps would be making a custom format with the option NOTSORTED and placing the values in the desired order. Then using the PRELOADFMT option for the variable along with other options depending on use to help it work.&lt;/P&gt;
&lt;P&gt;An example:&lt;/P&gt;
&lt;PRE&gt;proc format;
value orderexample (notsorted)
23 = '23'
1  = '1'
18 = '18'
5  = '5'
;
run;

data example;
   input inorder value;
datalines;
1  45
5  16
18 11
23 0
;

proc report data=example;
   columns inorder value;
   define inorder /group order=data preloadfmt;
   format inorder orderexample.;
run;&lt;/PRE&gt;
&lt;P&gt;The Order=data is one of the helper options but note that the input data order is not the order the report shows for the variable INORDER. Only a few procedures support this option but may be helpful. In proc report the column would have to be a Group variable.&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 19:18:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743023#M29219</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-21T19:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743031#M29221</link>
      <description>&lt;P&gt;I think another approach may be to ignore the whole sort issue and take a step back before I even join the tables together.&lt;/P&gt;&lt;P&gt;Table 1 is the original table:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_1;
input SORT_ORDER KEY_VAR $;
CARDS;
1 1-2-7
2 1-2-4
3 1-2-5
4 1-2-8
5 1-2-9
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Table 2 is a new KEY_VAR that needs to be added into the original table:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_2;
input KEY_VAR $;
CARDS;
1-2-3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I insert the new KEY_VAR (1-2-3) from table have_2 before KEY_VAR 1-2-4 without moving any other observations from Table have_1.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_1;
input SORT_ORDER KEY_VAR $;
CARDS;
1 1-2-7
. 1-2-3
2 1-2-4
3 1-2-5
4 1-2-8
5 1-2-9
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So I insert the new var (1-2-3) based on the logic that 1-2-3 comes before 1-2-4. But I don't want to move the first obs (1-2-7) from its current position so I end up with:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_final;
input SORT_ORDER KEY_VAR $;
CARDS;
1 1-2-7
2 1-2-3
3 1-2-4
4 1-2-5
5 1-2-8
6 1-2-9
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I hope that makes more sense.&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, 21 May 2021 19:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743031#M29221</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2021-05-21T19:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743067#M29226</link>
      <description>&lt;P&gt;What &lt;STRONG&gt;in the data&lt;/STRONG&gt; tells that 1-2-3 should come before 1-2-4 but not before 1-2-7???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And just how does this relate to your "report" at all? If there are other variables involved then perhaps examining how the REPORT is made is the important part.&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 22:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743067#M29226</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-21T22:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743094#M29229</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;BR /&gt;In all cases where the key_var is new, it should be inserted in numeric order so 1-2-3 should come before 1-2-4. For existing key_var, they should be in the order specified by the sort_order variable. So the idea is to take the original report and manually insert the new points by examining the values and inserting them in numeric order. I have no control over the report design other than being the person who has to update it. Perhaps this is just something that has to be done on a case by case basis manually. Thanks for your assistance.</description>
      <pubDate>Sat, 22 May 2021 01:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743094#M29229</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2021-05-22T01:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743096#M29230</link>
      <description>&lt;P&gt;You don't need a sort order rule if the current master data set is (1) already in the desired order, and (2) all relevant values of the sort variable ("sortvar" below), are found at least once in the master data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You already stated that condition 1 is true.&amp;nbsp; So assuming (2) is also true, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set master;
  by key_var notsorted;
  if _n_=1 then do;
    declare hash h (dataset:'newdata',multidata:'Y');
	  h.definekey('key_var');    /* Was "definesortvar"*/
	  h.definedata(all:'Y');
	  h.definedone();
  end;

  output;

  if last.key_var=1 and h.find()=0 then do until (h.find_next()^=0);
	output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Actually (2) doesn't have to be entirely true. What you really need is that the NEWDATA data set contains no key_var value not already in MASTER.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've corrected some bad editing in my code above.&amp;nbsp; Also this program assumes that dataset NEWDATA has all the same variables as MASTER.&amp;nbsp; Otherwise extra variables from the last within-by-group observation in MASTER will be kept in the new observations added for the NEWDATA observations.&lt;/P&gt;</description>
      <pubDate>Sat, 22 May 2021 13:25:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743096#M29230</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-05-22T13:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743098#M29231</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; This looks like an interesting approach and I am eager to try it, but I get an error (DATA STEP Component Object failure. Aborted during the COMPILATION phase.) From everything I read on google it would seem to point to a syntax error but unfortunately I have no experience with hash so am having trouble pin-pointing it. Any suggestions?</description>
      <pubDate>Sat, 22 May 2021 03:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743098#M29231</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2021-05-22T03:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743118#M29234</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;In particular, for any two different records to be sorted there must be no ambiguity as to which one takes precedence of the other.&lt;/P&gt;
&lt;P&gt;(...)&lt;/P&gt;
&lt;P&gt;Can you provide a rule that is applicable to any two (SORT_ORDER, KEY_VAR) pairs?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/75160"&gt;@sas-inquirer&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The rule is SORT_ORDER takes precedence over KEY_VAR.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The rule must refer to &lt;EM&gt;values&lt;/EM&gt;, not only&amp;nbsp;&lt;EM&gt;variable names&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;Suppose that this is an existing record in the original table:&lt;/P&gt;
&lt;PRE&gt;SORT_ORDER KEY_VAR
42         3-5-7&lt;/PRE&gt;
&lt;P&gt;Now this new record is to be inserted:&lt;/P&gt;
&lt;PRE&gt;SORT_ORDER KEY_VAR
.          3-5-11&lt;/PRE&gt;
&lt;P&gt;A rule for a well-defined sort order based on &lt;FONT face="courier new,courier"&gt;SORT_ORDER&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;KEY_VAR&lt;/FONT&gt; must decide whether this new record would appear (somewhere)&amp;nbsp;&lt;EM&gt;before&lt;/EM&gt; or (somewhere)&amp;nbsp;&lt;EM&gt;after&lt;/EM&gt; the above existing record after insertion.&lt;/P&gt;</description>
      <pubDate>Sat, 22 May 2021 09:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743118#M29234</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-05-22T09:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743133#M29236</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/75160"&gt;@sas-inquirer&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; This looks like an interesting approach and I am eager to try it, but I get an error (DATA STEP Component Object failure. Aborted during the COMPILATION phase.) From everything I read on google it would seem to point to a syntax error but unfortunately I have no experience with hash so am having trouble pin-pointing it. Any suggestions?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;ANY time you get an error you should copy the log with all the procedure text and all notes, warnings as well as the message, open a text box on the forum with the &amp;lt;/&amp;gt; icon and paste the text. The text box is important because SAS often includes diagnostic information that depends text behavior and the message windows on this forum will reformat pasted text which makes those diagnostics less useful or easy to follow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With that said, look in the log or your code for something that includes two . in the syntax like this.that.something.&lt;/P&gt;
&lt;P&gt;The error you get most easily generated that way.&lt;/P&gt;</description>
      <pubDate>Sat, 22 May 2021 14:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743133#M29236</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-22T14:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743147#M29238</link>
      <description>&lt;P&gt;I don't quite understand your rule for inserting the new records. This would seem more logical:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input SORT_ORDER KEY_VAR $;
CARDS;
1 1-2-9
2 1-2-4
4 1-2-5
5 1-2-8
. 1-1-5
. 1-2-7
. 1-3-1
. 1-3-3
;

proc sort data=have out=have1; by key_var; run;

data have2;
retain last_order;
set have1;
temp_sort_order = sort_order;
if missing(temp_sort_order) then temp_sort_order = last_order;
else last_order = sort_order;
drop last_order;
run;

proc sort data=have2 out=have3; by temp_sort_order key_var; run;

data want;
set have3;
new_sort_order = _n_;
run;

proc print data=want noobs; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1621704480423.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59684i997AD0EDD1D246AF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1621704480423.png" alt="PGStats_0-1621704480423.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If not, please explain.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 May 2021 17:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743147#M29238</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-05-22T17:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743175#M29240</link>
      <description>@FreelanceReinhard&lt;BR /&gt;Right, the rule then would be any new record should be inserted in numerical order so in your example, 3-5-11 would be inserted after 3-5-7.</description>
      <pubDate>Sat, 22 May 2021 21:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743175#M29240</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2021-05-22T21:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743202#M29241</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/75160"&gt;@sas-inquirer&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;@FreelanceReinhard&lt;BR /&gt;Right, the rule then would be any new record should be inserted in numerical order so in your example, 3-5-11 would be inserted after 3-5-7.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Thanks. Unfortunately, the rules established so far violate the &lt;EM&gt;transitivity&lt;/EM&gt; condition and hence do not define a linear order (see the Wikipedia article I linked earlier).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider these three &lt;FONT face="courier new,courier"&gt;(SORT_ORDER, KEY_VAR)&lt;/FONT&gt; pairs:&lt;/P&gt;
&lt;PRE&gt;SORT_ORDER KEY_VAR
1          1-1-3
2          1-1-1
.          1-1-2&lt;/PRE&gt;
&lt;P&gt;We have&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face="courier new,courier"&gt;(1, 1-1-3) &amp;lt; (2, 1-1-1)&lt;/FONT&gt; because "&lt;SPAN&gt;&lt;A href="https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743010/highlight/true#M29217" target="_blank" rel="noopener"&gt;The rule is SORT_ORDER takes precedence over KEY_VAR.&lt;/A&gt;"&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;(2, 1-1-1) &amp;lt; (., 1-1-2)&lt;/FONT&gt; because "&lt;A href="https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743007/highlight/true#M29216" target="_blank" rel="noopener"&gt;The new KEY_VAR's are to be inserted based on their KEY_VAR numeric order&lt;/A&gt;"&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Yet,&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;(1, 1-1-3) &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&amp;gt;&lt;/FONT&gt;&lt;/STRONG&gt; (., 1-1-2)&lt;/FONT&gt; because, again,&amp;nbsp;&lt;SPAN&gt;"&lt;A href="https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743007/highlight/true#M29216" target="_blank" rel="noopener"&gt;The new KEY_VAR's are to be inserted based on their KEY_VAR numeric order&lt;/A&gt;".&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;SPAN&gt;Therefore it is &lt;EM&gt;impossible&lt;/EM&gt; to sort these three records in accordance with the rules. &lt;EM&gt;Each&lt;/EM&gt; of their six permutations violates at least one of the two rules.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 May 2021 09:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743202#M29241</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-05-23T09:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743518#M29252</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;. This is certainly the closest a solution has come. If the 1-3-1 and 1-3-3 fell in position 7 and 8 under new_sort_order it would be perfect, but I'm realizing this custom sort is not going to be possible. Thank you for your suggestion and time.</description>
      <pubDate>Tue, 25 May 2021 10:50:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743518#M29252</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2021-05-25T10:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743519#M29253</link>
      <description>@FreelanceReinhard - you are right. This is not a logical rule. I need to go back to my client and convince them to either create a new order with the new data included else accept a numerical order. Thanks so much for your time.</description>
      <pubDate>Tue, 25 May 2021 10:55:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743519#M29253</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2021-05-25T10:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: Custom sort order based on a predefined sort order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743520#M29254</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; thanks for your code. I liked the approach. Unfortunatly I cannot make it work for my needs. I think this is a case where automation is not possible.</description>
      <pubDate>Tue, 25 May 2021 10:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Custom-sort-order-based-on-a-predefined-sort-order/m-p/743520#M29254</guid>
      <dc:creator>sas-inquirer</dc:creator>
      <dc:date>2021-05-25T10:57:49Z</dc:date>
    </item>
  </channel>
</rss>

