<?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: Copy values across rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Copy-values-across-rows/m-p/32209#M6224</link>
    <description>although SAS does not "read ahead", this is not forecasting so just read it any way you want &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;   &lt;BR /&gt;
 &lt;BR /&gt;
For a base SAS table, using the POINT= option of the SET statement, you can "read in reverse".[pre]data updated_data ;&lt;BR /&gt;
  do _n_ = top to 1 by -1 ;&lt;BR /&gt;
    set your.data point= _n_  nobs= top ;&lt;BR /&gt;
    if not missing(rank) then old_rank= rank ; &lt;BR /&gt;
       else rank = old_rank ;&lt;BR /&gt;
    output ;&lt;BR /&gt;
  end ;&lt;BR /&gt;
  stop ;&lt;BR /&gt;
  drop old_rank ;&lt;BR /&gt;
run;[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
peterC</description>
    <pubDate>Thu, 11 Nov 2010 09:16:22 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2010-11-11T09:16:22Z</dc:date>
    <item>
      <title>Copy values across rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-values-across-rows/m-p/32207#M6222</link>
      <description>I have a data which looks like this and i want to copy the last obesrvation of height to all the previous rows of a given subject&lt;BR /&gt;
&lt;BR /&gt;
Sub Date   Age    Rank&lt;BR /&gt;
 1     xxx    23&lt;BR /&gt;
  1    xxy    20&lt;BR /&gt;
 1     xyy    13&lt;BR /&gt;
  1    xyx    16       1&lt;BR /&gt;
 2     xyx    12 &lt;BR /&gt;
 2    xyy     14&lt;BR /&gt;
 2    xzz     15       2&lt;BR /&gt;
&lt;BR /&gt;
I would like to copy the rank value of a given subject to all the previous dates (rows)</description>
      <pubDate>Wed, 10 Nov 2010 23:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-values-across-rows/m-p/32207#M6222</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-11-10T23:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Copy values across rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-values-across-rows/m-p/32208#M6223</link>
      <description>SAS doesn't really do a "read ahead", but it does readily do a "retain".  If the data always have the rank at the end, you could sort by sub and descending rank and then use a data step and retain to propagate the values to the "new" forward.&lt;BR /&gt;
&lt;BR /&gt;
Doc Muhlbaier&lt;BR /&gt;
Duke</description>
      <pubDate>Thu, 11 Nov 2010 00:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-values-across-rows/m-p/32208#M6223</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2010-11-11T00:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Copy values across rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-values-across-rows/m-p/32209#M6224</link>
      <description>although SAS does not "read ahead", this is not forecasting so just read it any way you want &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;   &lt;BR /&gt;
 &lt;BR /&gt;
For a base SAS table, using the POINT= option of the SET statement, you can "read in reverse".[pre]data updated_data ;&lt;BR /&gt;
  do _n_ = top to 1 by -1 ;&lt;BR /&gt;
    set your.data point= _n_  nobs= top ;&lt;BR /&gt;
    if not missing(rank) then old_rank= rank ; &lt;BR /&gt;
       else rank = old_rank ;&lt;BR /&gt;
    output ;&lt;BR /&gt;
  end ;&lt;BR /&gt;
  stop ;&lt;BR /&gt;
  drop old_rank ;&lt;BR /&gt;
run;[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
peterC</description>
      <pubDate>Thu, 11 Nov 2010 09:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-values-across-rows/m-p/32209#M6224</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-11-11T09:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Copy values across rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-values-across-rows/m-p/32210#M6225</link>
      <description>[pre]&lt;BR /&gt;
data have;&lt;BR /&gt;
   infile cards missover;&lt;BR /&gt;
   input Sub Date$ Age Rank;&lt;BR /&gt;
   cards;&lt;BR /&gt;
1 xxx 23&lt;BR /&gt;
1 xxy 20&lt;BR /&gt;
1 xyy 13&lt;BR /&gt;
1 xyx 16 1&lt;BR /&gt;
2 xyx 12 &lt;BR /&gt;
2 xyy 14&lt;BR /&gt;
2 xzz 15 2&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
data need;&lt;BR /&gt;
   merge have(drop=rank) have(keep=sub rank where=(not missing(rank)));&lt;BR /&gt;
   by sub;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 11 Nov 2010 12:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-values-across-rows/m-p/32210#M6225</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-11-11T12:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Copy values across rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-values-across-rows/m-p/32211#M6226</link>
      <description>good demo _null_ &lt;BR /&gt;
my backward solution pays no respect to subject&lt;BR /&gt;
  &lt;BR /&gt;
peterC</description>
      <pubDate>Thu, 11 Nov 2010 12:56:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-values-across-rows/m-p/32211#M6226</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-11-11T12:56:14Z</dc:date>
    </item>
  </channel>
</rss>

