<?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: sas code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sas-code/m-p/686656#M208413</link>
    <description>&lt;P&gt;thank you so much - it worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Sep 2020 09:38:23 GMT</pubDate>
    <dc:creator>mpangli</dc:creator>
    <dc:date>2020-09-25T09:38:23Z</dc:date>
    <item>
      <title>sas code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-code/m-p/686637#M208407</link>
      <description>&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;I want to be able to calculate the percentage change between the top value then the value below (CUML_VOL) and keep moving down a row and doing the same&lt;/P&gt;&lt;P&gt;so for the first line I want to be able to calculate the difference between 66040.047 and 65895.855 as a starting point.&lt;/P&gt;&lt;P&gt;i want the result to be displayed on the top row (but as you can see it stores it on the 2nd row and so on)&lt;/P&gt;&lt;P&gt;and to keep working down until it gets to a new UC_POD_EXT&amp;nbsp;&lt;/P&gt;&lt;P&gt;so in this case it would restart the calculation when it gets to UC_POD_EXT = 1346502&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is the code I tried:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data alldata;&lt;BR /&gt;set alldata;&lt;BR /&gt;retain percent_change;&lt;BR /&gt;by uc_pod_ext;&lt;BR /&gt;if last.uc_pod_ext then percent_change=0;&lt;BR /&gt;else&lt;BR /&gt;percent_change = lag(cuml_vol) - cuml_vol ;&lt;BR /&gt;run;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS output.PNG" style="width: 838px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49777i3418BBE7F0999A3D/image-size/large?v=v2&amp;amp;px=999" role="button" title="SAS output.PNG" alt="SAS output.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 08:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-code/m-p/686637#M208407</guid>
      <dc:creator>mpangli</dc:creator>
      <dc:date>2020-09-25T08:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: sas code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-code/m-p/686647#M208412</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;This:&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data alldata;
set alldata;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is a bad idea; if something untoward happens in the DATA step, you have destroyed your dataset.&lt;/P&gt;
&lt;P&gt;Do a "look-ahead":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge
  alldata
  alldata (
    firstobs=2
    keep=uc_pod_ext cuml_vol
    rename=(uc_pod_ext=_uc cuml_vol=_cuml)
  )
;
if uc_pod_ext = _uc
then percent_change = _cuml - cuml_vol;
else percent_change = 0;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested; for tested code, supply example data in usable form, namely a data step with datalines; do not post pictures, and post your code into a code box opened with the "little running man" button right next to the one indicated:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg"&gt;&lt;img src="https://communities.sas.com/skins/images/70F8802BAA6255D55FBEC62A8226FB10/responsive_peak/images/image_not_found.png" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 10:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-code/m-p/686647#M208412</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-25T10:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: sas code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-code/m-p/686656#M208413</link>
      <description>&lt;P&gt;thank you so much - it worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 09:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-code/m-p/686656#M208413</guid>
      <dc:creator>mpangli</dc:creator>
      <dc:date>2020-09-25T09:38:23Z</dc:date>
    </item>
  </channel>
</rss>

