<?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 Simple RETAIN Problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simple-RETAIN-Problem/m-p/386470#M92562</link>
    <description>&lt;P&gt;I am solving this problem but have got stuck.Can anyone help me out.&lt;/P&gt;&lt;P&gt;Thanks .&lt;/P&gt;</description>
    <pubDate>Wed, 09 Aug 2017 04:30:41 GMT</pubDate>
    <dc:creator>rajvir</dc:creator>
    <dc:date>2017-08-09T04:30:41Z</dc:date>
    <item>
      <title>Simple RETAIN Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-RETAIN-Problem/m-p/386470#M92562</link>
      <description>&lt;P&gt;I am solving this problem but have got stuck.Can anyone help me out.&lt;/P&gt;&lt;P&gt;Thanks .&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 04:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-RETAIN-Problem/m-p/386470#M92562</guid>
      <dc:creator>rajvir</dc:creator>
      <dc:date>2017-08-09T04:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: Simple RETAIN Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-RETAIN-Problem/m-p/386475#M92567</link>
      <description>&lt;P&gt;Please include the question directly in the post. Users will not download attachments. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 04:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-RETAIN-Problem/m-p/386475#M92567</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-09T04:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: Simple RETAIN Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-RETAIN-Problem/m-p/386486#M92576</link>
      <description>&lt;P&gt;So it really depends on what they mean by "after the third observation has been read".&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14394iCDB66D41C18A3B59/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;First I would use the term &lt;STRONG&gt;observations&lt;/STRONG&gt; to refer to records in a SAS dataset, but this program is reading &lt;STRONG&gt;lines&lt;/STRONG&gt;&amp;nbsp;from a raw data file.&lt;/P&gt;
&lt;P&gt;Second do they mean after the third line is read and before the assignment statement executes? or after the assignment statement has executed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The value of COUNT when the third line is &lt;STRONG&gt;read&lt;/STRONG&gt;&amp;nbsp;by the INPUT statement will be &lt;STRONG&gt;130&lt;/STRONG&gt; since the value that was output at the end of the second iteration of the data step is still there since it is being retain. You get to 130 by adding the 10 and 20 to the initial value of 100.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now what the result will be after the assignment statement executes depends on how the source file is formatted. If the third line has at least three spaces on it (something that CANNOT be determined from the photograph you posted) then TENS will be missing and COUNT will stay at 130.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if the third line has less than three characters on it then SAS will go to the next line to find two characters and so TENS will be 4 and the COUNT total with 134.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try it yourself.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename dat temp;
data _null_;
  input str $3. ;
  file dat ;
  len=lengthn(str);
  put @2 str $varying2. len ;
cards;
 10
 20

 40
 50
;
run;
data test;
  infile dat ;
  input tens 2-3 ;
  retain count 100;
  count + tens;
  put (_n_ tens count) (=) ;
run;

data _null_;
  input str $char3. ;
  file dat ;
  len=lengthn(str);
  put str $char3. ;
cards;
 10
 20

 40
 50
;
run;
data test;
  infile dat ;
  input tens 2-3 ;
  retain count 100;
  count + tens;
  put (_n_ tens count) (=) ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 06:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-RETAIN-Problem/m-p/386486#M92576</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-08-09T06:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: Simple RETAIN Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-RETAIN-Problem/m-p/386719#M92658</link>
      <description>&lt;P&gt;Hey Thankyou so much &amp;nbsp;Tom for a detailed explanation ..&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 17:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-RETAIN-Problem/m-p/386719#M92658</guid>
      <dc:creator>rajvir</dc:creator>
      <dc:date>2017-08-09T17:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Simple RETAIN Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-RETAIN-Problem/m-p/386762#M92675</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/158053"&gt;@rajvir&lt;/a&gt;&amp;nbsp;Please mark Tom's solution as the correct answer (not this post!).&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 18:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-RETAIN-Problem/m-p/386762#M92675</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-09T18:44:39Z</dc:date>
    </item>
  </channel>
</rss>

