<?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: Generate a new variable that reverses the order of an existing variable. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911220#M83232</link>
    <description>&lt;P&gt;Just for some fun. Here is&amp;nbsp; a SAS/IML solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input X Y Z;
cards;
10    11     21
2     12   22
40   13    23
4    14    24
80    15    25
;
run;
proc iml;
use have nobs nobs;
read all var {x y z};
close;
xx=x[nobs:1];
create want var {x y z xx};
append;
close;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jan 2024 03:13:32 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-01-11T03:13:32Z</dc:date>
    <item>
      <title>Generate a new variable that reverses the order of an existing variable.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911074#M83218</link>
      <description>&lt;DIV&gt;Suppose I have&amp;nbsp; 3 variables&amp;nbsp; (X, Y, and Z)&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; obs &amp;nbsp; X&amp;nbsp; &amp;nbsp; Y&amp;nbsp; &amp;nbsp; &amp;nbsp;Z&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; 11&amp;nbsp; &amp;nbsp; &amp;nbsp;21&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;12 &amp;nbsp; 22&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp;40&amp;nbsp; &amp;nbsp;13&amp;nbsp; &amp;nbsp; 23 &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 14&amp;nbsp; &amp;nbsp; 24 &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp;80&amp;nbsp; &amp;nbsp; 15&amp;nbsp; &amp;nbsp; 25&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;I want to create a new variable called XX that reverses the order of variable X while preserving the order of the other variables.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; obs &amp;nbsp; X &amp;nbsp; Y &amp;nbsp; &amp;nbsp; Z &amp;nbsp; &amp;nbsp; XX&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; 11&amp;nbsp; &amp;nbsp; 21&amp;nbsp; &amp;nbsp; &amp;nbsp;80&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp;12 &amp;nbsp; 22&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 40&amp;nbsp; 13 &amp;nbsp; 23&amp;nbsp; &amp;nbsp; 40&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp;14 &amp;nbsp; 24&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; 80&amp;nbsp; &amp;nbsp;15 &amp;nbsp; 25&amp;nbsp; &amp;nbsp; 10&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Could you provide guidance on how to write SAS code to generate the second data set?&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Thanks&lt;/DIV&gt;</description>
      <pubDate>Wed, 10 Jan 2024 08:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911074#M83218</guid>
      <dc:creator>Golf</dc:creator>
      <dc:date>2024-01-10T08:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a new variable that reverses the order of an existing variable.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911075#M83219</link>
      <description>&lt;P&gt;Is there anything in your dataset which denotes groups?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the dataset as posted, I'd do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data second;
set have (keep=x rename=(x=xx));
n = _n_;
run;

proc sort data=second;
by n descending;
run;

data want;
merge
  have
  second (drop=n)
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2024 08:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911075#M83219</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-01-10T08:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a new variable that reverses the order of an existing variable.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911079#M83220</link>
      <description>&lt;P&gt;Alternatively, you can use a second SET statement with a&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p00hxg3x8lwivcn1f0e9axziw57y.htm#p0u2yq8x2b1fu4n1m0d5hzam9hjv" target="_blank" rel="noopener"&gt;POINT= option&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have nobs=n;
_n_=n-_n_+1;
set have(keep=x rename=(x=xx)) point=_n_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jan 2024 08:41:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911079#M83220</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-01-10T08:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a new variable that reverses the order of an existing variable.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911089#M83221</link>
      <description>Thank You so much.</description>
      <pubDate>Wed, 10 Jan 2024 09:58:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911089#M83221</guid>
      <dc:creator>Golf</dc:creator>
      <dc:date>2024-01-10T09:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a new variable that reverses the order of an existing variable.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911097#M83222</link>
      <description>&lt;P&gt;You can use the POINt= for this (no sorting).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input X Y Z;
cards;
10    11     21
2     12   22
40   13    23
4    14    24
80    15    25
;
run;
proc print data=have;
run;


data want;
  set have nobs=nobs curobs=curobs;
  point=nobs-curobs+1;
  set have(keep=x rename=(x=xx)) point=point;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2024 11:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911097#M83222</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-01-10T11:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a new variable that reverses the order of an existing variable.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911100#M83223</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;, I didn't notice your solution and wrote almost exactly the same &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2024 11:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911100#M83223</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-01-10T11:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a new variable that reverses the order of an existing variable.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911120#M83224</link>
      <description>Thank You</description>
      <pubDate>Wed, 10 Jan 2024 13:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911120#M83224</guid>
      <dc:creator>Golf</dc:creator>
      <dc:date>2024-01-10T13:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a new variable that reverses the order of an existing variable.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911220#M83232</link>
      <description>&lt;P&gt;Just for some fun. Here is&amp;nbsp; a SAS/IML solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input X Y Z;
cards;
10    11     21
2     12   22
40   13    23
4    14    24
80    15    25
;
run;
proc iml;
use have nobs nobs;
read all var {x y z};
close;
xx=x[nobs:1];
create want var {x y z xx};
append;
close;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2024 03:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911220#M83232</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-01-11T03:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a new variable that reverses the order of an existing variable.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911270#M83235</link>
      <description>Thank You.</description>
      <pubDate>Thu, 11 Jan 2024 14:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generate-a-new-variable-that-reverses-the-order-of-an-existing/m-p/911270#M83235</guid>
      <dc:creator>Golf</dc:creator>
      <dc:date>2024-01-11T14:13:22Z</dc:date>
    </item>
  </channel>
</rss>

