<?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: Question: _n_ not change? in SAS Software for Learning Community</title>
    <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Question-n-not-change/m-p/772863#M185</link>
    <description>&lt;P&gt;Incomplete data step will not run, no DATA at the top&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The _n_ variable indicates how many times the data step executes, i.e. hits the bottom of the code and starts over.&lt;/P&gt;
&lt;P&gt;Where you are using _n_ is in a loop. So the value that it has at the start of the DO loop stays the same until the loop finishes and then hits the second end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I understand what you want try this:&lt;/P&gt;
&lt;PRE&gt;data example;
   do Group='Placebo', 'Active';
		do Subj=1 to 5;
		    ID+1;
			input Score @; 
			output; 			
		end;
	end;
datalines;
250 222 230 210 199
166 183 123 129 234
;
run;&lt;/PRE&gt;
&lt;P&gt;The statement ID+1 implies the ID value is retained across iterations of the data step and each time the statement is encountered in the loop 1 is added.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Oct 2021 19:31:51 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-10-07T19:31:51Z</dc:date>
    <item>
      <title>Question: _n_ not change?</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Question-n-not-change/m-p/772852#M183</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Hi, I have the following data step. But I find that the ID (_n_) is always equal to 1. &lt;BR /&gt;Should it be 1, 2, ...10?&lt;BR /&gt;Thanks!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data Easyway;
	do Group='Placebo', 'Active';

		do Subj=1 to 5;
		    ID = _n_;
			input Score @; 
			output; 			
		end;
	end;
	datalines;
250 222 230 210 199
166 183 123 129 234
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 19:26:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Question-n-not-change/m-p/772852#M183</guid>
      <dc:creator>jz127323</dc:creator>
      <dc:date>2021-10-07T19:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Question: _n_ not change?</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Question-n-not-change/m-p/772862#M184</link>
      <description>&lt;P&gt;Why would _N_ change?&amp;nbsp; You didn't do anything to make it change.&amp;nbsp; Like assigning it a value.&amp;nbsp; Or starting the next iteration of the data step, which is what normally makes _N_ increment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the difference between SUBJ and ID in your dataset?&lt;/P&gt;
&lt;P&gt;If you want ID to be 1 when GROUP is 'Placebo' and 2 then it is 'Active' then set its value inside the outer DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do Group='Placebo', 'Active';
   ID+1;
   do SUBJ=1 to 5;
   ...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Oct 2021 19:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Question-n-not-change/m-p/772862#M184</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-07T19:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Question: _n_ not change?</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Question-n-not-change/m-p/772863#M185</link>
      <description>&lt;P&gt;Incomplete data step will not run, no DATA at the top&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The _n_ variable indicates how many times the data step executes, i.e. hits the bottom of the code and starts over.&lt;/P&gt;
&lt;P&gt;Where you are using _n_ is in a loop. So the value that it has at the start of the DO loop stays the same until the loop finishes and then hits the second end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I understand what you want try this:&lt;/P&gt;
&lt;PRE&gt;data example;
   do Group='Placebo', 'Active';
		do Subj=1 to 5;
		    ID+1;
			input Score @; 
			output; 			
		end;
	end;
datalines;
250 222 230 210 199
166 183 123 129 234
;
run;&lt;/PRE&gt;
&lt;P&gt;The statement ID+1 implies the ID value is retained across iterations of the data step and each time the statement is encountered in the loop 1 is added.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 19:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Question-n-not-change/m-p/772863#M185</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-07T19:31:51Z</dc:date>
    </item>
  </channel>
</rss>

