<?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: move variable to specific position in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833268#M35776</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329198"&gt;@Smitha9&lt;/a&gt;&amp;nbsp;said&lt;/P&gt;
&lt;P&gt;... "&lt;SPAN&gt;the output after the edit/add messed the order of the variables" ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Are you saying that variables were in the desired order prior to the edit/add step?&amp;nbsp; If so, show that code, which likely can be modified to generate variables in the desired order.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Sep 2022 00:11:59 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-09-14T00:11:59Z</dc:date>
    <item>
      <title>move variable to specific position</title>
      <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833146#M35756</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a dataset with 10 variables:&lt;/P&gt;&lt;P&gt;a&amp;nbsp; b&amp;nbsp; c&amp;nbsp; d&amp;nbsp; &amp;nbsp;e&amp;nbsp; &amp;nbsp;f&amp;nbsp; &amp;nbsp;g&amp;nbsp; &amp;nbsp;h&amp;nbsp; &amp;nbsp;i&amp;nbsp; &amp;nbsp;j&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to change the position of variable " j" to second position and&amp;nbsp; "d" to 10th position.&lt;/P&gt;&lt;P&gt;a&amp;nbsp; &amp;nbsp;j&amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp;c&amp;nbsp; &amp;nbsp;e&amp;nbsp; f&amp;nbsp; &amp;nbsp;g&amp;nbsp; &amp;nbsp;h&amp;nbsp; &amp;nbsp;i&amp;nbsp; &amp;nbsp;d&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I there any other way other than using retain? A short way.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 14:13:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833146#M35756</guid>
      <dc:creator>Smitha9</dc:creator>
      <dc:date>2022-09-13T14:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: move variable to specific position</title>
      <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833152#M35757</link>
      <description>&lt;P&gt;Yes, the short way is to not move it in the data set. Leave it where it is. Later when outputting something (a report or table) then you can specify the exact location of each column, PROC PRINT and PROC TABULATE and PROC REPORT (and other procedures) make this simple.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 14:16:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833152#M35757</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-13T14:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: move variable to specific position</title>
      <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833160#M35758</link>
      <description>&lt;P&gt;I think I'm in a minority on this, but I do occasionally reorder variables, even though it's not needed for analysis or reports (but even in these situations it can be convenient to have the variables stored in a particular order).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do it primarialy because I often view the data using the display component of SAS, or the SAS universal viewer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's how I would suggest&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if 0 then set have (keep=a) have (keep=j) have;
  set have;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The "if 0 then set" statement at the beginning obligates the SAS compiler to order the program data vector with a as the leftmost, j as the second, and then all other variables in their original order.&amp;nbsp; This happens even though actual data input happens only with the second SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 14:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833160#M35758</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-09-13T14:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: move variable to specific position</title>
      <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833163#M35759</link>
      <description>&lt;P&gt;Well, that's not a minority, there's 1 in favor and 1 opposed. But ... why not create a view with SQL or a view with a data step that re-orders the columns (and/or removes columns) if it helps when looking at the data set?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 15:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833163#M35759</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-13T15:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: move variable to specific position</title>
      <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833188#M35763</link>
      <description>&lt;P&gt;Now we're even a majority :&lt;FONT face="helvetica"&gt;-&lt;/FONT&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd suggest a minor change to the first SET statement to address the requirement regarding variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;d&lt;/FONT&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 0 then set have(keep=a j) have(drop=d);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Sep 2022 17:05:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833188#M35763</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-09-13T17:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: move variable to specific position</title>
      <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833202#M35767</link>
      <description>&lt;P&gt;My real problem with the request to re-arrange columns is the same as my problem with many requests where someone has decided on a solution, and doesn't really want to tell us why they have decided on this solution; they haven't even told us what the overall problem is. It is the &lt;A href="https://xyproblem.info/" target="_self"&gt;XY problem&lt;/A&gt;, it may be the wrong solution, an inefficient solution or it may be the right solution, we don't know because the person never tells us the reason they want to do this. And based on past experience, even when we ask directly to understand the problem, which I see that I did not do in this case, the user is often reluctant to tell us. This is inefficient for the user, and inefficient for those of us trying to help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And thus (for example), when the user sees columns in this order APR AUG DEC FEB ... and they really want the columns in the order JAN FEB MAR APR ..., they decide to ask the question about how to rearrange columns, and a better method of getting these columns in the right order in the first place never gets discussed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329198"&gt;@Smitha9&lt;/a&gt;&amp;nbsp;, why do you need to re-arrange columns? Explain why you need columns in a specific order, please.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 18:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833202#M35767</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-13T18:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: move variable to specific position</title>
      <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833244#M35768</link>
      <description>Hi,&lt;BR /&gt;The order is automated for the next team who goes through the data. I have been asked to edit a variable and add a variable. the output after the edit/add messed the order of the variables. There are like 30variables and that has a specific order for the next team to process. So I want to shortcut way to do this instead writing retain and name all the 30variables in order.&lt;BR /&gt;thanks</description>
      <pubDate>Tue, 13 Sep 2022 20:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833244#M35768</guid>
      <dc:creator>Smitha9</dc:creator>
      <dc:date>2022-09-13T20:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: move variable to specific position</title>
      <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833247#M35771</link>
      <description>&lt;P&gt;So the next team has used code such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;temperature -- pressure&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and if you change the order of variables things get all screwed up?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 20:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833247#M35771</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-13T20:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: move variable to specific position</title>
      <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833249#M35772</link>
      <description>&lt;P&gt;So you need to specify the order then somehow, manually unfortunately. If you have the order in a list or Excel file then it could be automated but since it's a one time process may as well just hardcode it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My lazy way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql FEEDBACK;
select * 
from sashelp.class as t1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Check the log and copy the code, reordering the columns needed manually once - making sure comma's are kept consistent. Done.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want_ordered as
         select T1.Name, T1.Sex, T1.Age, T1.Weight, T1.Height
           from SASHELP.CLASS T1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329198"&gt;@Smitha9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi,&lt;BR /&gt;The order is automated for the next team who goes through the data. I have been asked to edit a variable and add a variable. the output after the edit/add messed the order of the variables. There are like 30variables and that has a specific order for the next team to process. So I want to shortcut way to do this instead writing retain and name all the 30variables in order.&lt;BR /&gt;thanks&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 21:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833249#M35772</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-13T21:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: move variable to specific position</title>
      <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833252#M35773</link>
      <description>This is really easy in proc sql if I understand what you want&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;Create table work.example&lt;BR /&gt;as Select var1, var2,....&lt;BR /&gt;from work.datasetname;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;then put it in the select list in the order you want. The name of the dataset and where its stored will vary of course. If its not in a permanent library already you would have to import the data.</description>
      <pubDate>Tue, 13 Sep 2022 21:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833252#M35773</guid>
      <dc:creator>noetsi</dc:creator>
      <dc:date>2022-09-13T21:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: move variable to specific position</title>
      <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833267#M35775</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Now we're even a majority :&lt;FONT face="helvetica"&gt;-&lt;/FONT&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd suggest a minor change to the first SET statement to address the requirement regarding variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;d&lt;/FONT&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 0 then set have(keep=a j) have(drop=d);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sure, as long as J follows A in the original data set.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 00:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833267#M35775</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-09-14T00:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: move variable to specific position</title>
      <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833268#M35776</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329198"&gt;@Smitha9&lt;/a&gt;&amp;nbsp;said&lt;/P&gt;
&lt;P&gt;... "&lt;SPAN&gt;the output after the edit/add messed the order of the variables" ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Are you saying that variables were in the desired order prior to the edit/add step?&amp;nbsp; If so, show that code, which likely can be modified to generate variables in the desired order.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 00:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833268#M35776</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-09-14T00:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: move variable to specific position</title>
      <link>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833322#M35777</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329198"&gt;@Smitha9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi,&lt;BR /&gt;The order is automated for the next team who goes through the data. I have been asked to edit a variable and add a variable. the output after the edit/add messed the order of the variables. There are like 30variables and that has a specific order for the next team to process. So I want to shortcut way to do this instead writing retain and name all the 30variables in order.&lt;BR /&gt;thanks&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I get the very strong impression that the entire system needs to be re-designed here, so that this re-arranging of variables in a data set is not needed, but since we don't know all the requirements, its impossible to advise. Re-designing the entire system would of course take time, but would result in more efficient code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its a tradeoff, re-ordering the variables may be a quick fix; re-designing the system has long-term benefits but doesn't help in the short run. (Yes, I understand this, and have been in this situation on many occasions, and often choose the short term quick fix).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And its still not clear to me that re-ordering the variable is the long-term solution; you could code the re-ordering of variables today, only to find out that the each time thereafter more re-ordering of variables will be needed.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 13:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/move-variable-to-specific-position/m-p/833322#M35777</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-14T13:01:23Z</dc:date>
    </item>
  </channel>
</rss>

