<?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 Question about RETAIN statement. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Question-about-RETAIN-statement/m-p/341483#M78174</link>
    <description>&lt;P&gt;I was learning about the RETAIN statement and came across a paper about it (RETAIN or NOT? Is LAG Far Behind? by Venky Chakravarthy).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The example is about using the retain statement to replace missing value with substituted data (substitute with the last observation).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was confused with a line in the example data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The example is like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA SYSTOLIC2;
INPUT PTNO SBP;
CARDS;
1 120
1 .
1 140
2 150
2 130
2 .
3 135
3 .
3 .
3 .
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data impute2 ;
set systolic2 ;
by ptno ;
retain newsbp ;
if first.ptno then newsbp = . ; *I was confused by this line.;
if not missing(sbp) then newsbp = sbp ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The data step creates a new variable called &lt;STRONG&gt;newsbp &lt;/STRONG&gt;to replace the missing value in the &lt;STRONG&gt;sbp&lt;/STRONG&gt; variable with the last observation.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I tried to delete the line that confuses me and the output and log was the same with the example.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Do we really need to set the first &lt;STRONG&gt;newsbp&lt;/STRONG&gt; of a &lt;STRONG&gt;ptno&lt;/STRONG&gt; missing to make the data step work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since all the &lt;STRONG&gt;sbp&lt;/STRONG&gt; of&lt;CODE&gt; first.ptno&lt;FONT face="arial,helvetica,sans-serif"&gt; is not missing, w&lt;/FONT&gt;&lt;/CODE&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;hat is&lt;/FONT&gt; the purpose of setting the first &lt;STRONG&gt;newsbp&lt;/STRONG&gt; missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be great if anyone could help, thanks! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Mar 2017 09:00:28 GMT</pubDate>
    <dc:creator>ppchennn</dc:creator>
    <dc:date>2017-03-16T09:00:28Z</dc:date>
    <item>
      <title>Question about RETAIN statement.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-RETAIN-statement/m-p/341483#M78174</link>
      <description>&lt;P&gt;I was learning about the RETAIN statement and came across a paper about it (RETAIN or NOT? Is LAG Far Behind? by Venky Chakravarthy).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The example is about using the retain statement to replace missing value with substituted data (substitute with the last observation).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was confused with a line in the example data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The example is like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA SYSTOLIC2;
INPUT PTNO SBP;
CARDS;
1 120
1 .
1 140
2 150
2 130
2 .
3 135
3 .
3 .
3 .
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data impute2 ;
set systolic2 ;
by ptno ;
retain newsbp ;
if first.ptno then newsbp = . ; *I was confused by this line.;
if not missing(sbp) then newsbp = sbp ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The data step creates a new variable called &lt;STRONG&gt;newsbp &lt;/STRONG&gt;to replace the missing value in the &lt;STRONG&gt;sbp&lt;/STRONG&gt; variable with the last observation.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I tried to delete the line that confuses me and the output and log was the same with the example.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Do we really need to set the first &lt;STRONG&gt;newsbp&lt;/STRONG&gt; of a &lt;STRONG&gt;ptno&lt;/STRONG&gt; missing to make the data step work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since all the &lt;STRONG&gt;sbp&lt;/STRONG&gt; of&lt;CODE&gt; first.ptno&lt;FONT face="arial,helvetica,sans-serif"&gt; is not missing, w&lt;/FONT&gt;&lt;/CODE&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;hat is&lt;/FONT&gt; the purpose of setting the first &lt;STRONG&gt;newsbp&lt;/STRONG&gt; missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be great if anyone could help, thanks! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 09:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-RETAIN-statement/m-p/341483#M78174</guid>
      <dc:creator>ppchennn</dc:creator>
      <dc:date>2017-03-16T09:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Question about RETAIN statement.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-RETAIN-statement/m-p/341484#M78175</link>
      <description>&lt;P&gt;It is useless in this specific example but,as you say, if there was a ptno with first observation missing,&lt;BR /&gt;it would avoid to report the spb from the previous ptno.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 09:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-RETAIN-statement/m-p/341484#M78175</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-03-16T09:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: Question about RETAIN statement.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-RETAIN-statement/m-p/341486#M78177</link>
      <description>&lt;P&gt;At first, I thought the&lt;STRONG&gt; by ptno&lt;/STRONG&gt; line is enough for avoiding the problem of getting the observation from the previous ptno.&lt;BR /&gt;I tried to change the example sbp data and got the idea of what you mean.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for the help!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 09:16:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-RETAIN-statement/m-p/341486#M78177</guid>
      <dc:creator>ppchennn</dc:creator>
      <dc:date>2017-03-16T09:16:41Z</dc:date>
    </item>
  </channel>
</rss>

