<?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: Proc sort for character coloumns having numeric values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281320#M57028</link>
    <description>&lt;P&gt;That's not what your data has. Are you trying to replace the ID and create your own ID? That's a different question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is why I've stated you should state your requirements. Please try stating them as clearly as possible from the beginning to the end. Not taking the time to formulate your question clearly is a majority of the issue. You need to understand your problem before you can solve, or we can help you.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jun 2016 01:25:29 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-06-30T01:25:29Z</dc:date>
    <item>
      <title>Proc sort for character coloumns having numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281266#M57001</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I have two datasets B1 and B2 and i want to sort both datasets by first column can i do it dyanmically without indicating the name of teh column ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;B1&lt;/P&gt;&lt;P&gt;NUMBER ITEMS CODES&lt;BR /&gt;2 222223 2222&lt;BR /&gt;2 222228 2288&lt;BR /&gt;7 141111 545454&lt;BR /&gt;7 999999 5623&lt;BR /&gt;3 15151515 454545&lt;BR /&gt;1 8888888&lt;BR /&gt;484888&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;b2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID ITEMS CODES&lt;BR /&gt;2 1151515 746467&lt;BR /&gt;2 1151313 746957&lt;BR /&gt;6 155444 48784&lt;BR /&gt;6 155255 48784&lt;BR /&gt;5 7884878 234454&lt;BR /&gt;1 7515787 4864487&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro xc;&lt;/P&gt;&lt;P&gt;proc sort data=B_&amp;amp;i out= c_&amp;amp;i;&lt;/P&gt;&lt;P&gt;by ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%xc;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;i want to order by first column for B1 and B2 . So I have used this&lt;/P&gt;&lt;P&gt;%macro xc(i);&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set sashelp.vcolumn;&lt;BR /&gt;where upcase(libname) = 'WORK' and upcase(memname) = upcase("B_&amp;amp;i");&lt;BR /&gt;if _n_ = 1&lt;BR /&gt;then do;&lt;BR /&gt;&amp;nbsp; call symput('varname',name);&lt;BR /&gt;&amp;nbsp; stop;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=B_&amp;amp;i out=c_&amp;amp;i;&lt;BR /&gt;by &amp;amp;varname;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%xc(1);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;what if My B2 Dataset looks like below&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;b2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID ITEMS CODES&lt;BR /&gt;LIC&amp;nbsp; 1151515 746467&lt;BR /&gt;LIC&amp;nbsp; 1551547 48784&lt;BR /&gt;KKK 7884878 234454&lt;BR /&gt;KKK 7515787 4864487&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 20:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281266#M57001</guid>
      <dc:creator>hexx18</dc:creator>
      <dc:date>2016-06-29T20:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort for character coloumns having numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281272#M57005</link>
      <description>&lt;P&gt;So what if your dataset looks like that? Does it not work?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 21:02:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281272#M57005</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-29T21:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort for character coloumns having numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281274#M57007</link>
      <description>&lt;P&gt;Actually Number&amp;nbsp;and &amp;nbsp;id coloumns are character and i changed them to numeric to use in proc sort but&amp;nbsp; when if i &amp;nbsp;encounter chacter data in ID coulumn and its a problem and now i am unable to sort&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 21:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281274#M57007</guid>
      <dc:creator>hexx18</dc:creator>
      <dc:date>2016-06-29T21:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort for character coloumns having numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281283#M57012</link>
      <description>&lt;P&gt;was just checking instead can i add a column in B1 and B2&amp;nbsp; as count saying that&amp;nbsp; when number is 2 then 1 but when number changes to 7 then count+ 1 . same way for b2 . The count varibale should be dyanmic for B1 and B2 when i do some logic it should work for B1 and B2 irrespective whether the first column is numeric or character&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;B1&lt;/P&gt;&lt;P&gt;NUMBER ITEMS CODES&lt;BR /&gt;2 222223 2222&lt;BR /&gt;2 222228 2288&lt;BR /&gt;7 141111 545454&lt;BR /&gt;7 999999 5623&lt;BR /&gt;3 15151515 454545&lt;BR /&gt;1 8888888&lt;BR /&gt;484888&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;b2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID ITEMS CODES&lt;BR /&gt;LIC&amp;nbsp; 1151515 746467&lt;BR /&gt;LIC&amp;nbsp; 1551547 48784&lt;BR /&gt;KKK 7884878 234454&lt;BR /&gt;KKK 7515787 4864487&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;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 21:16:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281283#M57012</guid>
      <dc:creator>hexx18</dc:creator>
      <dc:date>2016-06-29T21:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort for character coloumns having numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281286#M57014</link>
      <description>&lt;P&gt;How are you unable to sort? A character column sorts alphabetically. The code above doesn't require a numeric column.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What at do you want that your not getting?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 21:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281286#M57014</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-29T21:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort for character coloumns having numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281287#M57015</link>
      <description>&lt;P&gt;Still not clear. What's your use case? The issue isn't a character column, but I don't know what your logic is.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;State what you need, not what you think the problem is.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 21:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281287#M57015</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-29T21:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort for character coloumns having numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281288#M57016</link>
      <description>&lt;P&gt;Frankly speaking you no longer make sense. Do yo want to sort or add columns according to a specific rule (that may involve sorting)? Very different tasks indeed. Please rephrase and elaborate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 21:22:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281288#M57016</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-06-29T21:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort for character coloumns having numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281293#M57018</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I have three data sets&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;B1&lt;/P&gt;&lt;P&gt;NUMBER ITEMS CODES&lt;BR /&gt;2 222223 2222&lt;BR /&gt;2 222228 2288&lt;BR /&gt;7 141111 545454&lt;BR /&gt;7 999999 5623&lt;BR /&gt;3 15151515 454545&lt;BR /&gt;1 8888888&lt;BR /&gt;484888&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;b2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID ITEMS CODES&lt;BR /&gt;2 1151515 746467&lt;BR /&gt;2 1151313 746957&lt;BR /&gt;6 155444 48784&lt;BR /&gt;6 155255 48784&lt;BR /&gt;5 7884878 234454&lt;BR /&gt;1 7515787 4864487&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;b3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;pin ITEMS CODES&lt;BR /&gt;LIC&amp;nbsp; 1151515 746467&lt;BR /&gt;LIC&amp;nbsp; 1551547 48784&lt;BR /&gt;KKK 7884878 234454&lt;BR /&gt;KKK 7515787 4864487&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for all three tables except first column all others are same and first column is character&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and i am taking first coulmn into macro variable&amp;nbsp; &amp;amp;varname&amp;nbsp; as shown above and i am doing sorting&amp;nbsp; but my b1 and b2 datsets doesnot get sorted by first coulum can anyone help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 21:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281293#M57018</guid>
      <dc:creator>hexx18</dc:creator>
      <dc:date>2016-06-29T21:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort for character coloumns having numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281315#M57026</link>
      <description>&lt;P&gt;I modified the macro very slightly to take a dataset name, rather than of the form name_i&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works for me, the numerical variables sort numerically and the character ones sort alphabetically. If this doesn't work, explain in DETAIL what is wrong, with a data example and your code/log if an error is generated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xc(datain);
data _null_;
set sashelp.vcolumn;
where upcase(libname) = 'WORK' and upcase(memname) = upcase("&amp;amp;datain");
if _n_ = 1
then do;
  call symputx('varname',name);
  stop;
end;
run;
proc sort data=&amp;amp;datain out=&amp;amp;datain._Sorted;
by &amp;amp;varname;
run;
%mend;

data b1;
input NUMBER ITEMS CODES;
cards;
2 222223 2222
2 222228 2288
7 141111 545454
7 999999 5623
3 15151515 454545
1 8888888 484888
;
run;

data b2;
input ID ITEMS CODES;
cards;
2 1151515 746467
2 1151313 746957
6 155444 48784
6 155255 48784
5 7884878 234454
1 7515787 4864487
;
run;

data b3;
input pin $ ITEMS CODES;
cards;
LIC  1151515 746467
LIC  1551547 48784
KKK 7884878 234454
KKK 7515787 4864487
;
run;

%xc(b1);
%xc(b2);
%xc(b3);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jun 2016 00:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281315#M57026</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-30T00:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort for character coloumns having numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281318#M57027</link>
      <description>&lt;P&gt;when i use below code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data xx;&lt;BR /&gt;input NUMBER$ ITEMS$;&lt;BR /&gt;datalines;&lt;BR /&gt;0 222223&lt;BR /&gt;1 222228&lt;BR /&gt;3 141111&lt;BR /&gt;4 999999&lt;BR /&gt;19 15151515&lt;BR /&gt;18 8888888&amp;nbsp;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=xx out=yy;&lt;BR /&gt;by number items;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the output is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;0&amp;nbsp;222223&lt;BR /&gt;1&amp;nbsp;222228&lt;BR /&gt;18&amp;nbsp;8888888&lt;BR /&gt;19&amp;nbsp;15151515&lt;BR /&gt;3&amp;nbsp;141111&lt;BR /&gt;4&amp;nbsp;999999&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but i want them to be 0 1 3 4 ---&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 01:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281318#M57027</guid>
      <dc:creator>hexx18</dc:creator>
      <dc:date>2016-06-30T01:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort for character coloumns having numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281320#M57028</link>
      <description>&lt;P&gt;That's not what your data has. Are you trying to replace the ID and create your own ID? That's a different question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is why I've stated you should state your requirements. Please try stating them as clearly as possible from the beginning to the end. Not taking the time to formulate your question clearly is a majority of the issue. You need to understand your problem before you can solve, or we can help you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 01:25:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281320#M57028</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-30T01:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort for character coloumns having numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281351#M57040</link>
      <description>&lt;P&gt;The sort order is correct. Your sort column look snumeric but is in fact character so it gets sorted alphabetically. The proper order in that case is 1 18 3 ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you want can be achieved by&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xx;
input NUMBER ITEMS $;
datalines;
0 222223
1 222228
3 141111
4 999999
19 15151515
18 8888888 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So remove the dollar sign behind NUMBER. probably ITEMS deserves the same treatment. And add a space before the dollar sign for clarity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 06:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sort-for-character-coloumns-having-numeric-values/m-p/281351#M57040</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-06-30T06:29:17Z</dc:date>
    </item>
  </channel>
</rss>

