<?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: Attempting to different first row of derived column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Attempting-to-different-first-row-of-derived-column/m-p/588077#M168018</link>
    <description>&lt;P&gt;A less elegant way than above:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x;
datalines;
100
350
760
900
1200
2000
;
run;

data want (drop=y rename=(y2=y));
set have;
y = x;
y2 = x-lag(x);
if y2 = . then y2 = y;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Sep 2019 02:00:35 GMT</pubDate>
    <dc:creator>maguiremq</dc:creator>
    <dc:date>2019-09-12T02:00:35Z</dc:date>
    <item>
      <title>Attempting to different first row of derived column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Attempting-to-different-first-row-of-derived-column/m-p/588073#M168016</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am still quite new with SAS and I am currently trying to derive a new column in which each row is pretty much the increment that the other row increased by. So for instance, if I have data 'X', I am trying to derive column 'Y':&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; Y&lt;BR /&gt;100 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 100&lt;/P&gt;&lt;P&gt;350 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 250&lt;/P&gt;&lt;P&gt;760 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 410&amp;nbsp;&lt;/P&gt;&lt;P&gt;900 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 140&lt;/P&gt;&lt;P&gt;1200 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 300&lt;/P&gt;&lt;P&gt;2000 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 800&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently using this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN style="background: white; margin: 0px; color: navy; font-family: 'Courier New';"&gt;data&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="background: white; margin: 0px; color: black; font-family: 'Courier New';"&gt; want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; margin: 0px; color: blue; font-family: 'Courier New';"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background: white; margin: 0px; color: black; font-family: 'Courier New';"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; margin: 0px; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; margin: 0px; color: black; font-family: 'Courier New';"&gt;Y=dif(X);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; margin: 0px; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; margin: 0px; color: blue; font-family: 'Courier New';"&gt;by&lt;/SPAN&gt;&lt;SPAN style="background: white; margin: 0px; color: black; font-family: 'Courier New';"&gt; /*insert personal sorted hierarchy*/ &lt;/SPAN&gt;&lt;SPAN style="background: white; margin: 0px; color: black; font-family: 'Courier New';"&gt;(first.ID,&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="background: white; margin: 0px; color: teal; font-family: 'Courier New';"&gt;.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="background: white; margin: 0px; color: black; font-family: 'Courier New';"&gt;,dif(X));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; margin: 0px; color: black; font-family: 'Courier New';"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I am trying to derive this column for different IDs, I order them to have the increments change with each new ID etc. This works well, however the problem I get is that the very first derived row is a blank for each new ID. However I would like to have the first row of Y to be the same as X shown above instead of a blank.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone could please assist me, that would be great!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 01:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Attempting-to-different-first-row-of-derived-column/m-p/588073#M168016</guid>
      <dc:creator>Bounce</dc:creator>
      <dc:date>2019-09-12T01:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Attempting to different first row of derived column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Attempting-to-different-first-row-of-derived-column/m-p/588076#M168017</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*No ID var*/
data want;
set have;
y=ifn(_n_=1,x,dif(x));
run;
/*for ID var*/
data want;
set have;
by id;
y=ifn(first.id,x,dif(x));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Sep 2019 01:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Attempting-to-different-first-row-of-derived-column/m-p/588076#M168017</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-12T01:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: Attempting to different first row of derived column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Attempting-to-different-first-row-of-derived-column/m-p/588077#M168018</link>
      <description>&lt;P&gt;A less elegant way than above:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x;
datalines;
100
350
760
900
1200
2000
;
run;

data want (drop=y rename=(y2=y));
set have;
y = x;
y2 = x-lag(x);
if y2 = . then y2 = y;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 02:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Attempting-to-different-first-row-of-derived-column/m-p/588077#M168018</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2019-09-12T02:00:35Z</dc:date>
    </item>
  </channel>
</rss>

