<?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: What does this Retain statement do in this Data Step? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262734#M269138</link>
    <description>&lt;P&gt;While all of this is true, it's important to note another aspect of the answer to your question. &amp;nbsp;In this DATA step, the RETAIN statement could be removed. &amp;nbsp;It's not doing anything useful. &amp;nbsp;The value of the retained variables gets replaced each time, so there is no benefit to RETAIN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, the variable TeamTotal is a running total across all teams and participants. &amp;nbsp;Since you are dropping TeamName, this is likely the result that you are looking for. &amp;nbsp;But if you really want a separate total for each team, you would need to add this statement before the first INPUT statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TeamTotal=0;&lt;/P&gt;</description>
    <pubDate>Sun, 10 Apr 2016 13:55:20 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-04-10T13:55:20Z</dc:date>
    <item>
      <title>What does this Retain statement do in this Data Step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262641#M269136</link>
      <description>&lt;PRE&gt;data total_points (drop=TeamName); 
length Event3 Event2 Event1 8. TeamName ParticipantName $8. ;
format Event2 z8. ;
retain TeamName Count ;
	input TeamName $ Count @ ;
		do i = 1 to Count ;
			input ParticipantName $ Event1 Event2 Event3 ;
				TeamTotal + (Event1 + Event2 + Event3);
					 output ;
		end ;
datalines; 
Knights 1 
Sue 6 8 8 
Kings 1 
Jane 9 7 8 
Knights 4 
John 7 7 7 
Lisa 8 9 9 
Fran 7 6 6 
Walter 9 8 10
;
proc print data=total_points;
run;&lt;/PRE&gt;&lt;P&gt;I've run this code with and without the Retain statement. It made no difference.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Apr 2016 04:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262641#M269136</guid>
      <dc:creator>junlue</dc:creator>
      <dc:date>2016-04-09T04:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: What does this Retain statement do in this Data Step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262650#M269137</link>
      <description>&lt;P&gt;Retain prevents the variable(s) from being initialized to MISSING every time the datastep iterates. This way you can carry a value over from one iteration step (observation) to the next. When a variable is also mentioned in an input statement (as is the case in your code) the value is overwritten as every execution of INPUT assigns a new value to these variables. So you can retain to your liking but you will not see the effect unless you dome stuff &lt;EM&gt;before&lt;/EM&gt; the input statement. But that is not the case in your example. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your example also note that RETAIN is always on for variables that are mentioned in a SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the doc:&lt;/P&gt;
&lt;P&gt;"It is redundant to name any of these items in a RETAIN statement, because their values are automatically retained from one iteration of the DATA step to the next:&lt;/P&gt;
&lt;DIV class="xis-listUnordered"&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV id="p0h8uss1ib82ztn1o9p8i35l9ies" class="xis-item"&gt;
&lt;DIV id="p0mf8zgko7tuzxn1cyxqebzn2c31" class="xis-paraSimpleFirst"&gt;variables that are read with a SET, MERGE, MODIFY or UPDATE statement&lt;/DIV&gt;
&lt;DIV class="xis-paraSimpleFirst"&gt;...&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;" &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, sometimes &lt;A href="http://support.sas.com/documentation/cdl/en/lestmtsref/68024/HTML/default/viewer.htm#p0t2ac0tfzcgbjn112mu96hkgg9o.htm" target="_self"&gt;RETAIN&lt;/A&gt; can be usefull even in this scenario if one decides to influence the variable order in the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;* edited for accuracy; added link *&lt;/P&gt;</description>
      <pubDate>Sat, 09 Apr 2016 11:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262650#M269137</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-04-09T11:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: What does this Retain statement do in this Data Step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262734#M269138</link>
      <description>&lt;P&gt;While all of this is true, it's important to note another aspect of the answer to your question. &amp;nbsp;In this DATA step, the RETAIN statement could be removed. &amp;nbsp;It's not doing anything useful. &amp;nbsp;The value of the retained variables gets replaced each time, so there is no benefit to RETAIN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, the variable TeamTotal is a running total across all teams and participants. &amp;nbsp;Since you are dropping TeamName, this is likely the result that you are looking for. &amp;nbsp;But if you really want a separate total for each team, you would need to add this statement before the first INPUT statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TeamTotal=0;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Apr 2016 13:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262734#M269138</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-10T13:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: What does this Retain statement do in this Data Step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262824#M269139</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80100"&gt;@junlue﻿&lt;/a&gt;&amp;nbsp;did any of responses help in any way?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 08:11:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262824#M269139</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-04-11T08:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: What does this Retain statement do in this Data Step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262826#M269140</link>
      <description>&lt;P&gt;Not really.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I'm also not quite sure what the "Trailing&amp;nbsp;@" does as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I understand it, the trailing&amp;nbsp;@ holds a record from the raw dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Take say the record "knights 4".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since this record is held in the input buffer, how can we input the other variables? The other variables are in the records below. But the input buffer is still occupied by the&amp;nbsp;record "knights 4".&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 08:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262826#M269140</guid>
      <dc:creator>junlue</dc:creator>
      <dc:date>2016-04-11T08:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: What does this Retain statement do in this Data Step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262829#M269141</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80100"&gt;@junlue﻿&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;@ holds the inpout for the next INPUT statement in the same datastep iteration. A special case&amp;nbsp;@@ holds the record even for the next iteration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the input is spread over consecutive records in the input you can choose to use multiple input statements but without the&amp;nbsp;@. Or you use the '/' in INPUT that instructs to load the next record and start reading at pos 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have (more than) a look at the &lt;A href="http://support.sas.com/documentation/cdl/en/lestmtsref/68024/HTML/default/viewer.htm#n0oaql83drile0n141pdacojq97s.htm" target="_self"&gt;doc&lt;/A&gt;&amp;nbsp;as the INPUT statement is very rich and also fundamental.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 08:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262829#M269141</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-04-11T08:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: What does this Retain statement do in this Data Step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262887#M269142</link>
      <description>&lt;P&gt;You're absolutely right about that.&amp;nbsp; The trailing @ should be removed.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 13:00:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-does-this-Retain-statement-do-in-this-Data-Step/m-p/262887#M269142</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-11T13:00:07Z</dc:date>
    </item>
  </channel>
</rss>

