<?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: How to sort colums in numeric order? How to replicate the observations? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69566#M19995</link>
    <description>Hi, John: &lt;BR /&gt;
&lt;BR /&gt;
I tried your codes. I did not get the results correct. So I think I can transpose the data, sort and transpose it back. I don't care about the column names.&lt;BR /&gt;
&lt;BR /&gt;
Thanks.&lt;BR /&gt;
&amp;gt; Gday sunrain,&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; A &lt;I&gt;PROC SORT&lt;/I&gt; should do the trick for rows.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; For columns, I would like to know if there's a&lt;BR /&gt;
&amp;gt; function/proc which will do this too.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; My current strategy would probably be:&lt;BR /&gt;
&amp;gt;  * PROC CONTENTS - to get a listing of the variables&lt;BR /&gt;
&amp;gt; * sorting that list&lt;BR /&gt;
&amp;gt; * creating a macro variable with the contents of the&lt;BR /&gt;
&amp;gt;  above list&lt;BR /&gt;
&amp;gt; * in a new datastep use the ATTRIB statement to with&lt;BR /&gt;
&amp;gt; the macro variable above &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; eg&lt;BR /&gt;
&amp;gt; [pre]&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; proc contents data = sashelp.adomsg out = a_contents&lt;BR /&gt;
&amp;gt; noprint;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; proc sort data = a_contents (keep = name) out =&lt;BR /&gt;
&amp;gt; a_sort;&lt;BR /&gt;
&amp;gt;    by name;&lt;BR /&gt;
&amp;gt; ;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data _null_;&lt;BR /&gt;
&amp;gt;    set a_sort;&lt;BR /&gt;
&amp;gt;   by name;&lt;BR /&gt;
&amp;gt;    retain sort_vars;&lt;BR /&gt;
&amp;gt; length sort_vars $100.;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt;    if _n_ = 1 then &lt;BR /&gt;
&amp;gt;    sort_vars = name;&lt;BR /&gt;
&amp;gt; else&lt;BR /&gt;
&amp;gt;       sort_vars = catx(' ', sort_vars, name);&lt;BR /&gt;
&amp;gt; all symput('sort_vars', sort_vars);&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; %put &amp;amp;sort_vars.;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data a_column_sorted;&lt;BR /&gt;
&amp;gt;    attrib &amp;amp;sort_vars. label = '';&lt;BR /&gt;
&amp;gt; set sashelp.adomsg;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; [/pre]&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I don't think PROC TRANSPOSE necessarily sorts the&lt;BR /&gt;
&amp;gt; columns, I think it'll probably list variables&lt;BR /&gt;
&amp;gt; according the order in which in comes across them.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; As for efficiency, I guess that really depends on&lt;BR /&gt;
&amp;gt; what the system can handle.  If you want to replicate&lt;BR /&gt;
&amp;gt; observations, you could have multiple OUTPUT&lt;BR /&gt;
&amp;gt; statements in your code.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; [/pre]&lt;BR /&gt;
&amp;gt; data a_replicated;&lt;BR /&gt;
&amp;gt;    set sashelp.adomsg;&lt;BR /&gt;
&amp;gt;   output;&lt;BR /&gt;
&amp;gt;  output;&lt;BR /&gt;
&amp;gt; un;&lt;BR /&gt;
&amp;gt;  &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data a_replicated2;&lt;BR /&gt;
&amp;gt;    set sashelp.adomsg&lt;BR /&gt;
&amp;gt;     sashelp.adomsg;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; [/pre]&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; The second one is concatenating the data with itself.</description>
    <pubDate>Thu, 26 May 2011 01:40:40 GMT</pubDate>
    <dc:creator>sunrain</dc:creator>
    <dc:date>2011-05-26T01:40:40Z</dc:date>
    <item>
      <title>How to sort colums in numeric order? How to replicate the observations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69564#M19993</link>
      <description>Hi, everyone:&lt;BR /&gt;
&lt;BR /&gt;
I just came out from the R world and started using SAS recently.&lt;BR /&gt;
In R, there is a function apply, where you can specify sort the data across the rows or columns. In SAS, do we have to transpose the data in order to use sort?&lt;BR /&gt;
&lt;BR /&gt;
Also I would like to replicate each observation for several times, is there an efficient way to do that? Or I can repeat the data for k times, concatenate them and sort the whole data by ID. I can use append recursively for that. Is that efficient considering my original data has million obs? &lt;BR /&gt;
&lt;BR /&gt;
Thank you in advance.&lt;BR /&gt;
Sunrain</description>
      <pubDate>Wed, 25 May 2011 21:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69564#M19993</guid>
      <dc:creator>sunrain</dc:creator>
      <dc:date>2011-05-25T21:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort colums in numeric order? How to replicate the observations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69565#M19994</link>
      <description>Gday sunrain,&lt;BR /&gt;
&lt;BR /&gt;
A &lt;I&gt;PROC SORT&lt;/I&gt; should do the trick for rows.&lt;BR /&gt;
&lt;BR /&gt;
For columns, I would like to know if there's a function/proc which will do this too.&lt;BR /&gt;
&lt;BR /&gt;
My current strategy would probably be:&lt;BR /&gt;
 * PROC CONTENTS - to get a listing of the variables&lt;BR /&gt;
 * sorting that list&lt;BR /&gt;
 * creating a macro variable with the contents of the above list&lt;BR /&gt;
 * in a new datastep use the ATTRIB statement to with the macro variable above &lt;BR /&gt;
&lt;BR /&gt;
eg&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
proc contents data = sashelp.adomsg out = a_contents noprint;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data = a_contents (keep = name) out = a_sort;&lt;BR /&gt;
   by name;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   set a_sort;&lt;BR /&gt;
&lt;BR /&gt;
   by name;&lt;BR /&gt;
&lt;BR /&gt;
   retain sort_vars;&lt;BR /&gt;
   length sort_vars $100.;&lt;BR /&gt;
&lt;BR /&gt;
   if _n_ = 1 then &lt;BR /&gt;
      sort_vars = name;&lt;BR /&gt;
   else&lt;BR /&gt;
      sort_vars = catx(' ', sort_vars, name);&lt;BR /&gt;
&lt;BR /&gt;
   call symput('sort_vars', sort_vars);&lt;BR /&gt;
run;&lt;BR /&gt;
%put &amp;amp;sort_vars.;&lt;BR /&gt;
&lt;BR /&gt;
data a_column_sorted;&lt;BR /&gt;
   attrib &amp;amp;sort_vars. label = '';&lt;BR /&gt;
   set sashelp.adomsg;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
I don't think PROC TRANSPOSE necessarily sorts the columns, I think it'll probably list variables according the order in which in comes across them.&lt;BR /&gt;
&lt;BR /&gt;
As for efficiency, I guess that really depends on what the system can handle.  If you want to replicate observations, you could have multiple OUTPUT statements in your code.&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
data a_replicated;&lt;BR /&gt;
   set sashelp.adomsg;&lt;BR /&gt;
&lt;BR /&gt;
   output;&lt;BR /&gt;
   output;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
&lt;BR /&gt;
data a_replicated2;&lt;BR /&gt;
   set sashelp.adomsg&lt;BR /&gt;
       sashelp.adomsg;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
The second one is concatenating the data with itself.</description>
      <pubDate>Wed, 25 May 2011 23:31:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69565#M19994</guid>
      <dc:creator>JohnT</dc:creator>
      <dc:date>2011-05-25T23:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort colums in numeric order? How to replicate the observations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69566#M19995</link>
      <description>Hi, John: &lt;BR /&gt;
&lt;BR /&gt;
I tried your codes. I did not get the results correct. So I think I can transpose the data, sort and transpose it back. I don't care about the column names.&lt;BR /&gt;
&lt;BR /&gt;
Thanks.&lt;BR /&gt;
&amp;gt; Gday sunrain,&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; A &lt;I&gt;PROC SORT&lt;/I&gt; should do the trick for rows.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; For columns, I would like to know if there's a&lt;BR /&gt;
&amp;gt; function/proc which will do this too.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; My current strategy would probably be:&lt;BR /&gt;
&amp;gt;  * PROC CONTENTS - to get a listing of the variables&lt;BR /&gt;
&amp;gt; * sorting that list&lt;BR /&gt;
&amp;gt; * creating a macro variable with the contents of the&lt;BR /&gt;
&amp;gt;  above list&lt;BR /&gt;
&amp;gt; * in a new datastep use the ATTRIB statement to with&lt;BR /&gt;
&amp;gt; the macro variable above &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; eg&lt;BR /&gt;
&amp;gt; [pre]&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; proc contents data = sashelp.adomsg out = a_contents&lt;BR /&gt;
&amp;gt; noprint;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; proc sort data = a_contents (keep = name) out =&lt;BR /&gt;
&amp;gt; a_sort;&lt;BR /&gt;
&amp;gt;    by name;&lt;BR /&gt;
&amp;gt; ;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data _null_;&lt;BR /&gt;
&amp;gt;    set a_sort;&lt;BR /&gt;
&amp;gt;   by name;&lt;BR /&gt;
&amp;gt;    retain sort_vars;&lt;BR /&gt;
&amp;gt; length sort_vars $100.;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt;    if _n_ = 1 then &lt;BR /&gt;
&amp;gt;    sort_vars = name;&lt;BR /&gt;
&amp;gt; else&lt;BR /&gt;
&amp;gt;       sort_vars = catx(' ', sort_vars, name);&lt;BR /&gt;
&amp;gt; all symput('sort_vars', sort_vars);&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; %put &amp;amp;sort_vars.;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data a_column_sorted;&lt;BR /&gt;
&amp;gt;    attrib &amp;amp;sort_vars. label = '';&lt;BR /&gt;
&amp;gt; set sashelp.adomsg;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; [/pre]&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I don't think PROC TRANSPOSE necessarily sorts the&lt;BR /&gt;
&amp;gt; columns, I think it'll probably list variables&lt;BR /&gt;
&amp;gt; according the order in which in comes across them.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; As for efficiency, I guess that really depends on&lt;BR /&gt;
&amp;gt; what the system can handle.  If you want to replicate&lt;BR /&gt;
&amp;gt; observations, you could have multiple OUTPUT&lt;BR /&gt;
&amp;gt; statements in your code.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; [/pre]&lt;BR /&gt;
&amp;gt; data a_replicated;&lt;BR /&gt;
&amp;gt;    set sashelp.adomsg;&lt;BR /&gt;
&amp;gt;   output;&lt;BR /&gt;
&amp;gt;  output;&lt;BR /&gt;
&amp;gt; un;&lt;BR /&gt;
&amp;gt;  &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data a_replicated2;&lt;BR /&gt;
&amp;gt;    set sashelp.adomsg&lt;BR /&gt;
&amp;gt;     sashelp.adomsg;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; [/pre]&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; The second one is concatenating the data with itself.</description>
      <pubDate>Thu, 26 May 2011 01:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69566#M19995</guid>
      <dc:creator>sunrain</dc:creator>
      <dc:date>2011-05-26T01:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort colums in numeric order? How to replicate the observations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69567#M19996</link>
      <description>Hi, John:&lt;BR /&gt;
&lt;BR /&gt;
Maybe I did not put my question clear. My goal is to sort data in "row-wise". That is sort every row independently, that is what R sort function do. In default, R sort sorts column wise.&lt;BR /&gt;
&lt;BR /&gt;
That is why transpose and sort and transpose back does not work.&lt;BR /&gt;
&lt;BR /&gt;
Sunrain.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; Gday sunrain,&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; A &lt;I&gt;PROC SORT&lt;/I&gt; should do the trick for rows.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; For columns, I would like to know if there's a&lt;BR /&gt;
&amp;gt; function/proc which will do this too.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; My current strategy would probably be:&lt;BR /&gt;
&amp;gt;  * PROC CONTENTS - to get a listing of the variables&lt;BR /&gt;
&amp;gt; * sorting that list&lt;BR /&gt;
&amp;gt; * creating a macro variable with the contents of the&lt;BR /&gt;
&amp;gt;  above list&lt;BR /&gt;
&amp;gt; * in a new datastep use the ATTRIB statement to with&lt;BR /&gt;
&amp;gt; the macro variable above &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; eg&lt;BR /&gt;
&amp;gt; [pre]&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; proc contents data = sashelp.adomsg out = a_contents&lt;BR /&gt;
&amp;gt; noprint;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; proc sort data = a_contents (keep = name) out =&lt;BR /&gt;
&amp;gt; a_sort;&lt;BR /&gt;
&amp;gt;    by name;&lt;BR /&gt;
&amp;gt; ;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data _null_;&lt;BR /&gt;
&amp;gt;    set a_sort;&lt;BR /&gt;
&amp;gt;   by name;&lt;BR /&gt;
&amp;gt;    retain sort_vars;&lt;BR /&gt;
&amp;gt; length sort_vars $100.;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt;    if _n_ = 1 then &lt;BR /&gt;
&amp;gt;    sort_vars = name;&lt;BR /&gt;
&amp;gt; else&lt;BR /&gt;
&amp;gt;       sort_vars = catx(' ', sort_vars, name);&lt;BR /&gt;
&amp;gt; all symput('sort_vars', sort_vars);&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; %put &amp;amp;sort_vars.;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data a_column_sorted;&lt;BR /&gt;
&amp;gt;    attrib &amp;amp;sort_vars. label = '';&lt;BR /&gt;
&amp;gt; set sashelp.adomsg;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; [/pre]&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I don't think PROC TRANSPOSE necessarily sorts the&lt;BR /&gt;
&amp;gt; columns, I think it'll probably list variables&lt;BR /&gt;
&amp;gt; according the order in which in comes across them.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; As for efficiency, I guess that really depends on&lt;BR /&gt;
&amp;gt; what the system can handle.  If you want to replicate&lt;BR /&gt;
&amp;gt; observations, you could have multiple OUTPUT&lt;BR /&gt;
&amp;gt; statements in your code.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; [/pre]&lt;BR /&gt;
&amp;gt; data a_replicated;&lt;BR /&gt;
&amp;gt;    set sashelp.adomsg;&lt;BR /&gt;
&amp;gt;   output;&lt;BR /&gt;
&amp;gt;  output;&lt;BR /&gt;
&amp;gt; un;&lt;BR /&gt;
&amp;gt;  &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data a_replicated2;&lt;BR /&gt;
&amp;gt;    set sashelp.adomsg&lt;BR /&gt;
&amp;gt;     sashelp.adomsg;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; [/pre]&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; The second one is concatenating the data with itself.</description>
      <pubDate>Thu, 26 May 2011 02:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69567#M19996</guid>
      <dc:creator>sunrain</dc:creator>
      <dc:date>2011-05-26T02:09:03Z</dc:date>
    </item>
    <item>
      <title>call sortn can work for this issue How to sort colums in numeric order?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69568#M19997</link>
      <description>Hi, every one:&lt;BR /&gt;
The command call sortn can work for this issue with some restriction.&lt;BR /&gt;
The varnames should be as x1-x10.&lt;BR /&gt;
&lt;BR /&gt;
Sunrain</description>
      <pubDate>Thu, 26 May 2011 18:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69568#M19997</guid>
      <dc:creator>sunrain</dc:creator>
      <dc:date>2011-05-26T18:04:02Z</dc:date>
    </item>
  </channel>
</rss>

