<?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: Data step  how to rearrange variable order in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/804859#M33439</link>
    <description>&lt;P&gt;One simple way to insure that the dataset is defined as you want is to have a template or skeleton dataset that you can use to set the variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set template(obs=0)  have;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Mar 2022 18:30:00 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-03-29T18:30:00Z</dc:date>
    <item>
      <title>Data step  how to rearrange variable order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/804855#M33435</link>
      <description />
      <pubDate>Tue, 29 Mar 2022 18:10:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/804855#M33435</guid>
      <dc:creator>purpleclothlady</dc:creator>
      <dc:date>2022-03-29T18:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Data step  how to rearrange variable order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/804856#M33436</link>
      <description>&lt;P&gt;Rarely is re-arranging the order of variables necessary. Why do you need to do this?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 18:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/804856#M33436</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-29T18:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: Data step  how to rearrange variable order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/804857#M33437</link>
      <description>&lt;P&gt;Hi All:&lt;/P&gt;
&lt;P&gt;I wander if there is any other ways to rearrange var. order in Data step ?&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Methods:&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;ATTRIB statement but we have to put length, format... . , which is not handy.&lt;/STRONG&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE lang="sas"&gt;data attrib_method;
    attrib day month year date sales length=3;
    set sashelp.retail(obs=5);
run;&lt;/PRE&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;If we use RETAIN before SET statement, will this sometimes accidentally change the variable values&lt;/STRONG&gt;
&lt;PRE lang="sas"&gt;data retain_method;
    retain day month year date sales;
    set sashelp.retail;
run;&lt;/PRE&gt;
&lt;P&gt;However, unless the sole purpose of a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="glossary-only-link" href="https://www.9to5sas.com/glossary/data-step/" target="_blank" rel="noopener"&gt;data step&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is to re-order&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="glossary-only-link" href="https://www.9to5sas.com/glossary/variables/" target="_blank" rel="noopener"&gt;variables&lt;/A&gt;, the use of RETAIN for this purpose can lead to unwanted results when the value of any ‘retained’ variable is carried over from one&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="glossary-only-link" href="https://www.9to5sas.com/glossary/data-step/" target="_blank" rel="noopener"&gt;data step&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;iteration to another.&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Are there any other ways?&lt;/P&gt;
&lt;P&gt;thanks all in advance.&lt;/P&gt;
&lt;P&gt;purple&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 18:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/804857#M33437</guid>
      <dc:creator>purpleclothlady</dc:creator>
      <dc:date>2022-03-29T18:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Data step  how to rearrange variable order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/804858#M33438</link>
      <description>&lt;P&gt;Hi Paige:&lt;/P&gt;
&lt;P&gt;I am working on large datasets with lots of variables, some data sets need to open in data step such as : subject, date, order...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you,&lt;/P&gt;
&lt;P&gt;Purple&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 18:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/804858#M33438</guid>
      <dc:creator>purpleclothlady</dc:creator>
      <dc:date>2022-03-29T18:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: Data step  how to rearrange variable order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/804859#M33439</link>
      <description>&lt;P&gt;One simple way to insure that the dataset is defined as you want is to have a template or skeleton dataset that you can use to set the variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set template(obs=0)  have;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Mar 2022 18:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/804859#M33439</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-29T18:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Data step  how to rearrange variable order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/804863#M33440</link>
      <description>&lt;P&gt;"Carryover" of values is not an issue when you use a SET statement.&amp;nbsp; ALL variables from a SAS data set are automatically retained.&amp;nbsp; So adding a RETAIN does not change that feature, and does not change which variables are being retained.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 18:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/804863#M33440</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-03-29T18:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Data step  how to rearrange variable order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/805013#M33446</link>
      <description>Hi Astounding:&lt;BR /&gt;thanks for clarification. I will test it.&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Mar 2022 11:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/805013#M33446</guid>
      <dc:creator>purpleclothlady</dc:creator>
      <dc:date>2022-03-30T11:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Data step  how to rearrange variable order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/805015#M33447</link>
      <description>Hi Tom:&lt;BR /&gt;here is an example:&lt;BR /&gt;data cars;&lt;BR /&gt;set sashelp.cars;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/*---WANT--- THE LAST 5 VARIABLES: ORIGIN, LENGTH, WHEELBASE,WEIGT ,MPG_HIGHWAY  TO BE SHOWN AS THE FIRST 5 VARIABLES*/&lt;BR /&gt;data template;&lt;BR /&gt;  input ORIGIN $ LENGTH WHEELBASE WEIGT MPG_HIGHWAY ;&lt;BR /&gt;	  datalines;&lt;BR /&gt;run;&lt;BR /&gt;data want;&lt;BR /&gt;   set template(obs=0)  cars;&lt;BR /&gt;run;&lt;BR /&gt;Question:&lt;BR /&gt;There are mixed char and numeric , I would need to specify that in input statement. &lt;BR /&gt;Is this the right way of creating template?&lt;BR /&gt;&lt;BR /&gt;thank you &lt;BR /&gt;</description>
      <pubDate>Wed, 30 Mar 2022 12:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/805015#M33447</guid>
      <dc:creator>purpleclothlady</dc:creator>
      <dc:date>2022-03-30T12:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: Data step  how to rearrange variable order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/805079#M33451</link>
      <description>&lt;P&gt;INPUT statement is for reading in values, not for DEFINING the variables.&lt;/P&gt;
&lt;P&gt;I would use LENGTH or ATTRIB to define the variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data template ;
  length origin $6 length wheelbase weight mpg_highway 8;
  label
    length = 'Length (IN)'
    wheelbase = 'Wheelbase (IN)'
    weight = 'Weight (LBS)'
    mpg_highway = 'MPG (Highway)'
  ;
  stop;
  call missing(of _all_);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And yes if your template defines the variable as numeric and the dataset you are trying to modify has it as character that is an ERROR that you would want the code to detect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way to impact the order is using the KEEP= (or DROP=) dataset option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set
   sashelp.cars(keep=origin)
   sashelp.cars(keep=length)
   sashelp.cars(keep=wheelbase)
   sashelp.cars(keep=weight)
   sashelp.cars(keep=mpg_highway)
   sashelp.cars
 ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Mar 2022 14:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/805079#M33451</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-30T14:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Data step  how to rearrange variable order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/805224#M33463</link>
      <description>&lt;P&gt;another method:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   format Origin Length Wheelbase Weight mpg_highway;
   set sashelp.cars;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Mar 2022 09:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/805224#M33463</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-03-31T09:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Data step  how to rearrange variable order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/805239#M33464</link>
      <description>&lt;P&gt;I like format or retain best.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 11:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/805239#M33464</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-03-31T11:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: Data step  how to rearrange variable order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/805264#M33466</link>
      <description>&lt;P&gt;Hi all:&lt;/P&gt;
&lt;P&gt;Thanks all for your help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They all work in Data Step but depending on your preference .&lt;/P&gt;
&lt;P&gt;Using 1. Retain(with caution), 2. Format, 3. Adding a Template dataset , 4. Attrib, 5. Keep/drop (this one will create more obs than original)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 13:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-step-how-to-rearrange-variable-order/m-p/805264#M33466</guid>
      <dc:creator>purpleclothlady</dc:creator>
      <dc:date>2022-03-31T13:42:17Z</dc:date>
    </item>
  </channel>
</rss>

