<?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: changing the value of a previous observation in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/changing-the-value-of-a-previous-observation/m-p/709093#M26684</link>
    <description>&lt;P&gt;You need a "look-ahead":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final;
merge
  overall
  overall (
    firstobs=2
    keep=n
    rename=(n=_n)
  )
;
total = sum(n,_n);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested; for tested code, provide your data as a data step with datalines.&lt;/P&gt;</description>
    <pubDate>Sat, 02 Jan 2021 19:35:21 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-01-02T19:35:21Z</dc:date>
    <item>
      <title>changing the value of a previous observation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/changing-the-value-of-a-previous-observation/m-p/709091#M26683</link>
      <description>&lt;P&gt;There are two observations and I would like to change the variable "total" in the first observation to "55" without hardcoding&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JeeAnTaeOo_0-1609615226241.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53179iF062B8A01E576C9B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JeeAnTaeOo_0-1609615226241.png" alt="JeeAnTaeOo_0-1609615226241.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;data final;&lt;BR /&gt;set overall;&lt;BR /&gt;total=n;&lt;BR /&gt;total+lag(n);&lt;BR /&gt;prpl=n/total;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code above is what I used to generate the table&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jan 2021 19:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/changing-the-value-of-a-previous-observation/m-p/709091#M26683</guid>
      <dc:creator>JeeAnTaeOo</dc:creator>
      <dc:date>2021-01-02T19:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: changing the value of a previous observation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/changing-the-value-of-a-previous-observation/m-p/709093#M26684</link>
      <description>&lt;P&gt;You need a "look-ahead":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final;
merge
  overall
  overall (
    firstobs=2
    keep=n
    rename=(n=_n)
  )
;
total = sum(n,_n);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested; for tested code, provide your data as a data step with datalines.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jan 2021 19:35:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/changing-the-value-of-a-previous-observation/m-p/709093#M26684</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-02T19:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: changing the value of a previous observation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/changing-the-value-of-a-previous-observation/m-p/709096#M26685</link>
      <description>&lt;P&gt;Looks like you are trying to generate TOTAL, not move it from one observation to another.&lt;/P&gt;
&lt;P&gt;You could just calculate the total and then combine it back onto the data set.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=overall;
  var n;
  output out=total sum=total;
run;

data final;
  set overall;
  if _n_=1 then set total(keep=total);
  prpl=n/total;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is a way to do it in one step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final;
  do until(eof1);
     set overall end=eof1;
     total+n;
  end;
  do until(eof2);
    set overall end=eof2;
    prpl=n/total;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Jan 2021 19:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/changing-the-value-of-a-previous-observation/m-p/709096#M26685</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-02T19:52:13Z</dc:date>
    </item>
  </channel>
</rss>

