<?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: Moving observations in the required position in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370865#M88565</link>
    <description>&lt;P&gt;First of all, post your code using the "little running man" icon. Saves us deleting the extra lines that one gets when code was posted into the main posting window.&lt;/P&gt;
&lt;P&gt;If the criteria is the % character in f1, then this does what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length f1 $8.;
input f1 $ id $ f2 $ f3 f4 f5;
datalines;
%NAs 1 A 73 87 65
%NAs 1 B 7 19 63
%NAs 1 C 24 24 64
%NAs 1 D 75 63 58
0-10 1 A 73 21 16
0-10 1 B 29 94 17
0-10 1 C 48 6 99
0-10 1 D 26 46 9
11-50 1 A 48 21 10
11-50 1 B 49 37 45
11-50 1 C 8 88 48
11-50 1 D 16 48 7
51-100 1 A 57 95 18
51-100 1 B 64 73 63
51-100 1 C 28 84 95
51-100 1 D 55 84 17
;
run;

data int1 int2;
set have;
if substr(f1,1,1) = '%'
then output int2;
else output int1;
run;

data want;
set
  int1
  int2
;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;  f1      id    f2    f3    f4    f5

0-10      1     A     73    21    16
0-10      1     B     29    94    17
0-10      1     C     48     6    99
0-10      1     D     26    46     9
11-50     1     A     48    21    10
11-50     1     B     49    37    45
11-50     1     C      8    88    48
11-50     1     D     16    48     7
51-100    1     A     57    95    18
51-100    1     B     64    73    63
51-100    1     C     28    84    95
51-100    1     D     55    84    17
%NAs      1     A     73    87    65
%NAs      1     B      7    19    63
%NAs      1     C     24    24    64
%NAs      1     D     75    63    58
&lt;/PRE&gt;</description>
    <pubDate>Tue, 27 Jun 2017 10:37:44 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-06-27T10:37:44Z</dc:date>
    <item>
      <title>Moving observations in the required position</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370863#M88564</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to get the set of observations in a dataset to the positions we want? For example the first 4 observations in the dataset HAVE1 should be moved to the last 4 observations as shown in &lt;FONT face="Courier New"&gt;WANT1 dataset below.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; HAVE1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;LENGTH&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; F1 &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$8.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;INPUT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; F1 $ ID$ F2 $ F3 F4 F5;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;%NAs 1 A 73 87 65&lt;/P&gt;&lt;P&gt;%NAs 1 B 7 19 63&lt;/P&gt;&lt;P&gt;%NAs 1 C 24 24 64&lt;/P&gt;&lt;P&gt;%NAs 1 D 75 63 58&lt;/P&gt;&lt;P&gt;0-10 1 A 73 21 16&lt;/P&gt;&lt;P&gt;0-10 1 B 29 94 17&lt;/P&gt;&lt;P&gt;0-10 1 C 48 6 99&lt;/P&gt;&lt;P&gt;0-10 1 D 26 46 9&lt;/P&gt;&lt;P&gt;11-50 1 A 48 21 10&lt;/P&gt;&lt;P&gt;11-50 1 B 49 37 45&lt;/P&gt;&lt;P&gt;11-50 1 C 8 88 48&lt;/P&gt;&lt;P&gt;11-50 1 D 16 48 7&lt;/P&gt;&lt;P&gt;51-100 1 A 57 95 18&lt;/P&gt;&lt;P&gt;51-100 1 B 64 73 63&lt;/P&gt;&lt;P&gt;51-100 1 C 28 84 95&lt;/P&gt;&lt;P&gt;51-100 1 D 55 84 17&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; WANT1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;LENGTH&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; F1 &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$8.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;INPUT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; F1 $ ID$ F2 $ F3 F4 F5;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;0-10 1 A 73 21 16&lt;/P&gt;&lt;P&gt;0-10 1 B 29 94 17&lt;/P&gt;&lt;P&gt;0-10 1 C 48 6 99&lt;/P&gt;&lt;P&gt;0-10 1 D 26 46 9&lt;/P&gt;&lt;P&gt;11-50 1 A 48 21 10&lt;/P&gt;&lt;P&gt;11-50 1 B 49 37 45&lt;/P&gt;&lt;P&gt;11-50 1 C 8 88 48&lt;/P&gt;&lt;P&gt;11-50 1 D 16 48 7&lt;/P&gt;&lt;P&gt;51-100 1 A 57 95 18&lt;/P&gt;&lt;P&gt;51-100 1 B 64 73 63&lt;/P&gt;&lt;P&gt;51-100 1 C 28 84 95&lt;/P&gt;&lt;P&gt;51-100 1 D 55 84 17&lt;/P&gt;&lt;P&gt;%NAs 1 A 73 87 65&lt;/P&gt;&lt;P&gt;%NAs 1 B 7 19 63&lt;/P&gt;&lt;P&gt;%NAs 1 C 24 24 64&lt;/P&gt;&lt;P&gt;%NAs 1 D 75 63 58&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 10:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370863#M88564</guid>
      <dc:creator>Data_User</dc:creator>
      <dc:date>2017-06-27T10:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Moving observations in the required position</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370865#M88565</link>
      <description>&lt;P&gt;First of all, post your code using the "little running man" icon. Saves us deleting the extra lines that one gets when code was posted into the main posting window.&lt;/P&gt;
&lt;P&gt;If the criteria is the % character in f1, then this does what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length f1 $8.;
input f1 $ id $ f2 $ f3 f4 f5;
datalines;
%NAs 1 A 73 87 65
%NAs 1 B 7 19 63
%NAs 1 C 24 24 64
%NAs 1 D 75 63 58
0-10 1 A 73 21 16
0-10 1 B 29 94 17
0-10 1 C 48 6 99
0-10 1 D 26 46 9
11-50 1 A 48 21 10
11-50 1 B 49 37 45
11-50 1 C 8 88 48
11-50 1 D 16 48 7
51-100 1 A 57 95 18
51-100 1 B 64 73 63
51-100 1 C 28 84 95
51-100 1 D 55 84 17
;
run;

data int1 int2;
set have;
if substr(f1,1,1) = '%'
then output int2;
else output int1;
run;

data want;
set
  int1
  int2
;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;  f1      id    f2    f3    f4    f5

0-10      1     A     73    21    16
0-10      1     B     29    94    17
0-10      1     C     48     6    99
0-10      1     D     26    46     9
11-50     1     A     48    21    10
11-50     1     B     49    37    45
11-50     1     C      8    88    48
11-50     1     D     16    48     7
51-100    1     A     57    95    18
51-100    1     B     64    73    63
51-100    1     C     28    84    95
51-100    1     D     55    84    17
%NAs      1     A     73    87    65
%NAs      1     B      7    19    63
%NAs      1     C     24    24    64
%NAs      1     D     75    63    58
&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Jun 2017 10:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370865#M88565</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-27T10:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Moving observations in the required position</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370896#M88571</link>
      <description>&lt;P&gt;You could produce a dummy without %, then sort with dummy, like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data temp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;set have1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;dummy=compress(translate(f1,'','%'));&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=temp out=want(drop=dummy);&lt;BR /&gt;by dummy;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or :&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table want as&lt;BR /&gt; select * from have1 order by prxchange('s/%//',-1,f1);&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 12:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370896#M88571</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2017-06-27T12:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: Moving observations in the required position</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370898#M88573</link>
      <description>&lt;P&gt;If your outputting categorical data like this, I find it far simpler to give each section a numerical order, you culd break it up and append it like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;has shown, but when the order becomes more complicated and you want to sort later on it just starts becoming harder. &amp;nbsp;An example:&lt;/P&gt;
&lt;P&gt;COL1 &amp;nbsp; &amp;nbsp;COL2&amp;nbsp;&lt;/P&gt;
&lt;P&gt;X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;y&lt;/P&gt;
&lt;P&gt;X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;/P&gt;
&lt;P&gt;Y &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the above order so:&lt;/P&gt;
&lt;P&gt;COL1 &amp;nbsp; &amp;nbsp;COL2 &amp;nbsp; &amp;nbsp;COL1_ORD &amp;nbsp;COL2_ORD&lt;/P&gt;
&lt;P&gt;X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;y &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;Y &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May seem like effort, but you can sort the above as much as you like, change the orders etc.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 12:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370898#M88573</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-27T12:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Moving observations in the required position</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370902#M88575</link>
      <description>&lt;P&gt;If you are sure that there are exactly 4 observations to move, the program is just like the solution to your earlier problem (moving one observation):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have (firstobs=5) have (obs=4);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 13:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370902#M88575</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-27T13:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: Moving observations in the required position</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370944#M88591</link>
      <description>&lt;P&gt;No, it's not the exact positions. The observation position may change. Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 14:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370944#M88591</guid>
      <dc:creator>Data_User</dc:creator>
      <dc:date>2017-06-27T14:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Moving observations in the required position</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370946#M88592</link>
      <description>&lt;P&gt;Thanks for your help. Much appreciate it.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 14:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370946#M88592</guid>
      <dc:creator>Data_User</dc:creator>
      <dc:date>2017-06-27T14:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Moving observations in the required position</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370951#M88594</link>
      <description>&lt;P&gt;No problem.&amp;nbsp; Just for the record, you can still do this in one step, using mildly similar tools:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have (where=(f1 ne : '%')) have (where=(f1 =: '%'));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested, but should work if you are identifying the "bottom" columns as those where F1 begins with "%".&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2017 14:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Moving-observations-in-the-required-position/m-p/370951#M88594</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-27T14:27:15Z</dc:date>
    </item>
  </channel>
</rss>

