<?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 rearrange output cols order in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935487#M367804</link>
    <description>&lt;P&gt;More explanation is needed. How are you going to do this "output"? What SAS PROC or other SAS command is going to produce this "output"? Is this "output" a SAS data set or a printed report or something else?&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jul 2024 14:43:16 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-07-11T14:43:16Z</dc:date>
    <item>
      <title>how to rearrange output cols order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935484#M367803</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to build multiple tables which always have 'Label' col and COLX, which x is non repeated number select from 1 to 99.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it a way I can always recorder or output my outputs use 'Label' as 1st col and COLs in the order from small number to 99?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Currently my outputs are always in a random col order. Any suggest or macro that can solve this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example: my output contain following cols:&lt;/P&gt;
&lt;P&gt;DS1:&lt;/P&gt;
&lt;P&gt;'Label', 'COL1', 'COL7', 'COL8', 'COL11', 'COL99'&lt;/P&gt;
&lt;P&gt;DS2:&lt;/P&gt;
&lt;P&gt;'COL7', 'COL1', 'COL88', 'COL99', COL1', 'Label'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 14:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935484#M367803</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-07-11T14:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange output cols order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935487#M367804</link>
      <description>&lt;P&gt;More explanation is needed. How are you going to do this "output"? What SAS PROC or other SAS command is going to produce this "output"? Is this "output" a SAS data set or a printed report or something else?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 14:43:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935487#M367804</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-07-11T14:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange output cols order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935489#M367805</link>
      <description>Maybe just output another dataset that contain correct col order? &lt;BR /&gt;data ds1_update;&lt;BR /&gt;set ds1;&lt;BR /&gt;...&lt;BR /&gt;Run;</description>
      <pubDate>Thu, 11 Jul 2024 14:44:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935489#M367805</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-07-11T14:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange output cols order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935491#M367806</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/448857"&gt;@stataq&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Maybe just output another dataset that contain correct col order? &lt;BR /&gt;data ds1_update;&lt;BR /&gt;set ds1;&lt;BR /&gt;...&lt;BR /&gt;Run;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Seems pointless to me to re-arrange columns within a data set. What is the reason you want this? How would this help?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 14:46:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935491#M367806</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-07-11T14:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange output cols order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935494#M367807</link>
      <description>&lt;P&gt;I hope to achieve a status that my outputs are organized in a good col order as a dataset. when I need to output them in file, I can directly use them without reorder the cols.&amp;nbsp; Maybe also easier for me to review the results when I just look at the dataset without proc print step. might be silly but make sense to me.&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 14:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935494#M367807</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-07-11T14:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange output cols order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935496#M367808</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;SPAN&gt;Seems pointless to me to re-arrange columns within a data set. What is the reason you want this? How would this help?&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;I often do pay attention to establishing column order, for two reasons:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;To examine the data with a data set viewer&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;In anticipation of using the double-dash technique for generating a variable list.&amp;nbsp; Say I have a dataset with (from left to right), an ID, some demographic variables, some financial variables, some education variables.&amp;nbsp; I often find myself using expressions like&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;leftmost_demographic_variable -- rightmost_demographic_var&lt;BR /&gt;to save a lot of typing where a list of variables would otherwise need to be explicitly typed.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Thu, 11 Jul 2024 15:14:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935496#M367808</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-07-11T15:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange output cols order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935499#M367810</link>
      <description>&lt;P&gt;The simplest way to reorder the variables is to take advantage of the fact that the RETAIN statement places the variables into the dataset, but does not define a type for them (unless you include an initial value in the RETAIN statement).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  retain label col1 col47 col99 ;
  set have;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to automate that then find a rule that sets the order of the columns in the way you want.&amp;nbsp; For your example I might be tempted to do something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have noprint out=contents; run;
proc sql noprint;
  select nliteral(name) into :varlist separated by ' '
  from contents
  ;
quit;
data want;
  retain label col1-col99;
  set have;
  keep &amp;amp;varlist;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 15:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-rearrange-output-cols-order/m-p/935499#M367810</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-11T15:37:18Z</dc:date>
    </item>
  </channel>
</rss>

