<?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 move a record to a specific place in a data set. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40311#M8185</link>
    <description>VAR is character variable, so "X" is an allowed value. VAR can be any capital letter. The records are sorted in descending order by the variable FREQUENCY.&lt;BR /&gt;
&lt;BR /&gt;
If the observation VAR="X" are among observations number 1 - 5, I want to have it has observation number 6.&lt;BR /&gt;
&lt;BR /&gt;
The example is narrowed down.</description>
    <pubDate>Thu, 14 Jan 2010 12:38:56 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-01-14T12:38:56Z</dc:date>
    <item>
      <title>How to move a record to a specific place in a data set.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40308#M8182</link>
      <description>In my data set there are 2 variables VAR and FREQUENCY.&lt;BR /&gt;
&lt;BR /&gt;
The number of records are 10 and the 10 values of VAR are unique.&lt;BR /&gt;
&lt;BR /&gt;
If VAR="X" is placed among observations number 1 - 5 I want to get it as observation number 6. The relative order of the 9 other observations should be kept.&lt;BR /&gt;
&lt;BR /&gt;
How can that be done?</description>
      <pubDate>Thu, 14 Jan 2010 10:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40308#M8182</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-01-14T10:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to move a record to a specific place in a data set.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40309#M8183</link>
      <description>Is this a real life problem, or just a narrowed down example?&lt;BR /&gt;
How does X relates to the other values of VAR? And how was the original sort order of data created?&lt;BR /&gt;
Without knowing the real purpose, I would suggest that you create a look-up table, which specifies the sort order according to VAR, join and then sort.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Thu, 14 Jan 2010 11:10:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40309#M8183</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2010-01-14T11:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to move a record to a specific place in a data set.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40310#M8184</link>
      <description>Yes... Quite an intriguing question.&lt;BR /&gt;
&lt;BR /&gt;
Knowing the purpose would help, perhaps to point out another alternative.&lt;BR /&gt;
&lt;BR /&gt;
Anyway, if I got this right, you want to reposition some observation within the dataset.&lt;BR /&gt;
&lt;BR /&gt;
Being X=3 for example, you could try this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data OUTDATA;&lt;BR /&gt;
set INDATA (where=(VAR ne 3)); * exclude the desired obs;&lt;BR /&gt;
output;&lt;BR /&gt;
if _N_ eq 6-1 then do;&lt;BR /&gt;
set INDATA (where=(VAR eq 3)); * include the desired obs&lt;BR /&gt;
output;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Thu, 14 Jan 2010 11:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40310#M8184</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2010-01-14T11:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to move a record to a specific place in a data set.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40311#M8185</link>
      <description>VAR is character variable, so "X" is an allowed value. VAR can be any capital letter. The records are sorted in descending order by the variable FREQUENCY.&lt;BR /&gt;
&lt;BR /&gt;
If the observation VAR="X" are among observations number 1 - 5, I want to have it has observation number 6.&lt;BR /&gt;
&lt;BR /&gt;
The example is narrowed down.</description>
      <pubDate>Thu, 14 Jan 2010 12:38:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40311#M8185</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-01-14T12:38:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to move a record to a specific place in a data set.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40312#M8186</link>
      <description>Now we understand the sort order.&lt;BR /&gt;
But not why "X" should be in obs 5. Should it always be in position 5, or depending on the situation?&lt;BR /&gt;
You could just rank your observations, and for VAR="X" re-rank it to 5 (and potentially change the existing no 5), and then sort the data.&lt;BR /&gt;
/Linus</description>
      <pubDate>Thu, 14 Jan 2010 12:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40312#M8186</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2010-01-14T12:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to move a record to a specific place in a data set.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40313#M8187</link>
      <description>Don't people on this forum simplify their problems?&lt;BR /&gt;
&lt;BR /&gt;
I simplify because I don't want to reveal confidental data, and I simplify because it should be easier to answer the question if  the example is narrowed down.&lt;BR /&gt;
&lt;BR /&gt;
In my data set is a frequency table. If the frequency for the capital letter "X" is among the 5 (FIVE) biggest I want to have it as observation number 6 (SIX). The other 9 records should keep their relative order.&lt;BR /&gt;
&lt;BR /&gt;
Please, don't ask me why I want to have the record with "X" as observation number 6, and only when it first was among records number 1 - 5. If the record with VAR="X" was placed among observations number 6 - 10 when I got the data set, nothing should be done.</description>
      <pubDate>Thu, 14 Jan 2010 13:32:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40313#M8187</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-01-14T13:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to move a record to a specific place in a data set.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40314#M8188</link>
      <description>ErnestoC, I believe no one here is interested about you're confidential data whatsoever.&lt;BR /&gt;
&lt;BR /&gt;
Sometimes questions here are dropped with so little information that the effort to give a proper answer is doubled (one to understand the question/scenario and the other to ACTUALLY give a proper solution).&lt;BR /&gt;
&lt;BR /&gt;
That said, I believe the suggestion (just swap the numeric VAR to a char one) I have posted before will solve you're trouble.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
      <pubDate>Thu, 14 Jan 2010 16:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40314#M8188</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2010-01-14T16:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to move a record to a specific place in a data set.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40315#M8189</link>
      <description>double post, please ignore.</description>
      <pubDate>Thu, 14 Jan 2010 16:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40315#M8189</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2010-01-14T16:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to move a record to a specific place in a data set.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40316#M8190</link>
      <description>This seems a bit complicated but I believe it works properly when the target(t) is not in the first 5 obs.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc plan seed=412257359;&lt;BR /&gt;
   factors x=10 f=1 of 70;&lt;BR /&gt;
   output out=test;&lt;BR /&gt;
   run;&lt;BR /&gt;
   quit;&lt;BR /&gt;
&lt;BR /&gt;
proc freq order=freq;&lt;BR /&gt;
   tables x / out=f;&lt;BR /&gt;
   weight f;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
%let t = 3;&lt;BR /&gt;
data test;&lt;BR /&gt;
   do g = 1 to 5;&lt;BR /&gt;
      set f(obs=5);&lt;BR /&gt;
      if x = &amp;amp;t then leave;&lt;BR /&gt;
      end;&lt;BR /&gt;
   if 1 le g le 5 then do;&lt;BR /&gt;
      do point=1 to g-1, g+1 to 6, g, 7 to nobs;         &lt;BR /&gt;
         set f point=point nobs=nobs;&lt;BR /&gt;
         output;&lt;BR /&gt;
         end;&lt;BR /&gt;
      end;&lt;BR /&gt;
   else do until(eof);&lt;BR /&gt;
      set f end=eof;&lt;BR /&gt;
      output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   stop;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 14 Jan 2010 16:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-move-a-record-to-a-specific-place-in-a-data-set/m-p/40316#M8190</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-01-14T16:54:23Z</dc:date>
    </item>
  </channel>
</rss>

