<?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: sort by multiple numeric var or one char that is concatenation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/966999#M376253</link>
    <description>&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;My eyes didnt catch the point related to proc sort&amp;nbsp; in this article&lt;/P&gt;</description>
    <pubDate>Tue, 20 May 2025 11:15:42 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2025-05-20T11:15:42Z</dc:date>
    <item>
      <title>sort by multiple numeric var or one char that is concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/966996#M376251</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Lets say i have a data set with many columns.&lt;/P&gt;
&lt;P&gt;Let's say I want to sort the data set by 4 columns (numeric columns)- X,W,Z,R&lt;/P&gt;
&lt;P&gt;Let's say that I also have another field called CAT that is concatenation of -X,W,Z,R (it is char var because have - between values).&lt;/P&gt;
&lt;P&gt;My question-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is better to sort: By X,W,Z,R&amp;nbsp; or by CAT? or maybe both are similar efficient?&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>Tue, 20 May 2025 10:36:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/966996#M376251</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-05-20T10:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple numeric var or one char that is concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/966997#M376252</link>
      <description>&lt;P&gt;Maxim 4.&lt;/P&gt;
&lt;P&gt;Try it and compare the results.&lt;/P&gt;</description>
      <pubDate>Tue, 20 May 2025 11:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/966997#M376252</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-05-20T11:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple numeric var or one char that is concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/966999#M376253</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;My eyes didnt catch the point related to proc sort&amp;nbsp; in this article&lt;/P&gt;</description>
      <pubDate>Tue, 20 May 2025 11:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/966999#M376253</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-05-20T11:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple numeric var or one char that is concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967000#M376254</link>
      <description>&lt;P&gt;I will try but since the data set is very big (100 million rows) then I want to know the logic which is better&lt;/P&gt;</description>
      <pubDate>Tue, 20 May 2025 11:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967000#M376254</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-05-20T11:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple numeric var or one char that is concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967002#M376255</link>
      <description>&lt;P&gt;Are the numeric values all the same length? If they are not, then you could get a different sort order comparing the numeric sort to the character sort. Consider the following example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input x w z r;
cards;
1 11 111 2
1 2 3 4
;
run;

data test;
set test;
cat=cat(x, w, z, r);
run;

proc sort data=test out=nums;
by x w z r;
run;

proc print data=nums;
run;

proc sort data=test out=chars;
by cat;
run;

proc print data=chars;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Remember that when sorting numeric values in a character variable, the 1's will sort before the 2's, etc. So 10 might come before 2 as in the following example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input numc $;
cards;
1
2
10
;
run;

proc sort data=test out=sorted;
by numc;
run;

proc print data=sorted;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 May 2025 11:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967002#M376255</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-05-20T11:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple numeric var or one char that is concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967009#M376258</link>
      <description>&lt;P&gt;thanks,&lt;/P&gt;
&lt;P&gt;all numeric with length 8.&lt;/P&gt;
&lt;P&gt;In bottom line, do you recommend sort by&amp;nbsp; &amp;nbsp;4numeric var: X,W,Z,R or by one char var&amp;nbsp; CATX('-',X,W,Z,R)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 May 2025 13:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967009#M376258</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-05-20T13:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple numeric var or one char that is concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967015#M376260</link>
      <description>All the more reason to conduct a real-life test.</description>
      <pubDate>Tue, 20 May 2025 13:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967015#M376260</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-05-20T13:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple numeric var or one char that is concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967029#M376261</link>
      <description>&lt;P&gt;I dont really care who come first ,most important that groups define by 4 columns be together for the next data analysis&lt;/P&gt;</description>
      <pubDate>Tue, 20 May 2025 14:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967029#M376261</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-05-20T14:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple numeric var or one char that is concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967031#M376262</link>
      <description>&lt;P&gt;So you posted the original question 4 hours ago.&amp;nbsp; Are you really saying that it would have taken longer than 4 hours to test it yourself?&lt;/P&gt;</description>
      <pubDate>Tue, 20 May 2025 14:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967031#M376262</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2025-05-20T14:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple numeric var or one char that is concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967035#M376264</link>
      <description>&lt;P&gt;From an efficiency/resource perspective, I would not expect a significant difference between sorting by 4 numeric variables or one character one. By "same length" I should clarify the same number of digits. A numeric length of 8 in SAS can mean &lt;EM&gt;up to&lt;/EM&gt; 15 significant digits. If the numeric variable values are not the same number of digits, then you can get a different order from 4 numeric variables versus one concatenated character one. And I think order does matter based on this part of your comment: "&lt;SPAN&gt;most important that groups define by 4 columns be together for the next data analysis"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As others have mentioned, testing this on your part is needed because only you can determine if you are getting the order you expect.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 May 2025 15:29:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967035#M376264</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-05-20T15:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple numeric var or one char that is concatenation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967037#M376265</link>
      <description>&lt;P&gt;Probably does not matter, but test.&lt;/P&gt;
&lt;P&gt;If you do want to make a concatenated variable then you need to worry about missing values and formatted length (not storage length) of the numeric variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values are floating point then DO NOT make a character variable. Too much risk of having different values look like the same thing when converted to a string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values are all the same display length (for example integers between 0 and 9)&amp;nbsp; then you could make a new variable using CATT() function, CATT(X,W,Z,R)&amp;nbsp; If not then perhaps you could force them to the same display length by perhaps use Z format?&amp;nbsp; Which will require more coding CATT(put(x,Z5.),put(w,Z5.),put(z,Z5.),put(r,Z5.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the order does not matter and the values are of variable display lengths (and there are not missing values) then use CATX() function do add some type of delimiter between the values so that 1,11,21,1 does not get mapped to the&amp;nbsp; same string&amp;nbsp; as (11,1,2,11). CATX('-',x,w,z,r)&lt;/P&gt;</description>
      <pubDate>Tue, 20 May 2025 15:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-numeric-var-or-one-char-that-is-concatenation/m-p/967037#M376265</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-05-20T15:57:14Z</dc:date>
    </item>
  </channel>
</rss>

