<?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: Retain question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain-question/m-p/446857#M112191</link>
    <description>&lt;P&gt;You can't do that because this statement executes on every observation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;GRP=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the largest value you could ever get for GRP with your program is 2.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Mar 2018 16:46:46 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-03-19T16:46:46Z</dc:date>
    <item>
      <title>Retain question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-question/m-p/446853#M112189</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The following question is copied from the below thread&lt;/P&gt;
&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-right lia-quilt-column-main-right"&gt;
&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-right"&gt;
&lt;DIV id="messagebodydisplay_0" class="lia-message-body"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Creating-a-Column-That-Groups-Data-Every-n-Rows/m-p/427080/highlight/false#M105290&amp;nbsp;" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Creating-a-Column-That-Groups-Data-Every-n-Rows/m-p/427080/highlight/false#M105290&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking to create a new column that groups my data every n rows. For example I have 1,000 rows, I would like to create a column that assigns the first 100 rows Group 1, the next 100 rows Group 2, and so on until the final row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question:&lt;/P&gt;
&lt;P&gt;I want to declare grp=1 at the beginning of the code and it doesn't work. I think it is natural to have such line. How can I make that line "grp=1" works?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
do n=1 to 1000;
output;
end;
run;

*SOLUTION;
data want;
set have;
retain grp 1;
if mod(n,100)=0 then grp+1;
run;

*WHY CANT I DECLARE GRP=1;

data want;
set have;
&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;GRP=1;&lt;/FONT&gt;&lt;/STRONG&gt;
retain grp;
if mod(n,100)=0 then grp+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 19 Mar 2018 16:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-question/m-p/446853#M112189</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-03-19T16:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Retain question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-question/m-p/446856#M112190</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The following question is copied from the below thread&lt;/P&gt;
&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-right lia-quilt-column-main-right"&gt;
&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-right"&gt;
&lt;DIV class="lia-message-body" id="messagebodydisplay_0"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Creating-a-Column-That-Groups-Data-Every-n-Rows/m-p/427080/highlight/false#M105290&amp;nbsp;" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Creating-a-Column-That-Groups-Data-Every-n-Rows/m-p/427080/highlight/false#M105290&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking to create a new column that groups my data every n rows. For example I have 1,000 rows, I would like to create a column that assigns the first 100 rows Group 1, the next 100 rows Group 2, and so on until the final row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question:&lt;/P&gt;
&lt;P&gt;I want to declare grp=1 at the beginning of the code and it doesn't work. I think it is natural to have such line. How can I make that line "grp=1" works?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When you use:&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;GRP=1;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;retain grp;&lt;BR /&gt;if mod(n,100)=0 then grp+1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first thing that happens to each record when read from have is to assign the value of 1 to GRP. Which overwrites any RETAINED value.&lt;/P&gt;
&lt;P&gt;Which is one reason that the RETAIN statement has the option of initializing a value. But it would still have headaches if the retained variable were in the data set as the value read from the set would replace any retain as well.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 16:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-question/m-p/446856#M112190</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-19T16:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Retain question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-question/m-p/446857#M112191</link>
      <description>&lt;P&gt;You can't do that because this statement executes on every observation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;GRP=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the largest value you could ever get for GRP with your program is 2.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 16:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-question/m-p/446857#M112191</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-19T16:46:46Z</dc:date>
    </item>
  </channel>
</rss>

