<?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: Sequnce number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62168#M13540</link>
    <description>hi ... yes that works but you are missing the point(s)&lt;BR /&gt;
&lt;BR /&gt;
#1/  _n_ works in that situation, but it does not always work since&lt;BR /&gt;
it counts passes through the data step, not observations added&lt;BR /&gt;
to the data set created in the data step&lt;BR /&gt;
&lt;BR /&gt;
in your SAS job, _n_ works since the number of passes through the &lt;BR /&gt;
data step is the same as the number of observations added to data&lt;BR /&gt;
set class&lt;BR /&gt;
&lt;BR /&gt;
#2/  this ... length SEQ_NO 8; ... is not needed since&lt;BR /&gt;
even without it the length  of SEQ_NO is 8</description>
    <pubDate>Fri, 14 Jan 2011 21:50:29 GMT</pubDate>
    <dc:creator>MikeZdeb</dc:creator>
    <dc:date>2011-01-14T21:50:29Z</dc:date>
    <item>
      <title>Sequnce number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62158#M13530</link>
      <description>Hi!&lt;BR /&gt;
&lt;BR /&gt;
I have a table to which I want to add a sequence no to uniquely identify records. &lt;BR /&gt;
What would be the best way to do this ?I have read about _n_ but not sure hot to use it.&lt;BR /&gt;
Any help would be appreciated.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Thu, 13 Jan 2011 17:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62158#M13530</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-13T17:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sequnce number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62159#M13531</link>
      <description>_n_ is not that &lt;I&gt;hot&lt;/I&gt;... &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;/*&amp;nbsp;add&amp;nbsp;obs&amp;nbsp;number&amp;nbsp;using&amp;nbsp;_n_&amp;nbsp;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;data&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;class;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;length&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;myObs&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#008080;font-family:Courier New;font-size:10pt;"&gt;8&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;sashelp.class;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;myObs&amp;nbsp;=&amp;nbsp;_n_;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;run&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;/*&amp;nbsp;check&amp;nbsp;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;proc&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;print&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;=class(&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;obs&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;=&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#008080;font-family:Courier New;font-size:10pt;"&gt;5&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;run&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;/*&amp;nbsp;on&amp;nbsp;lst&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;my&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Sex&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Age&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Height&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Weight&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Alfred&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;M&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;69.0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;112.5&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Alice&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;F&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;56.5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;84.0&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Barbara&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;F&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;65.3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;98.0&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Carol&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;F&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;62.8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;102.5&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Henry&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;M&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;63.5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;102.5&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2011 17:51:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62159#M13531</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2011-01-13T17:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: Sequnce number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62160#M13532</link>
      <description>hi ... you have to be careful using _n_ since it counts passes through the data step, it does not count observations, for example ...&lt;BR /&gt;
&lt;BR /&gt;
data males;&lt;BR /&gt;
set sashelp.class;&lt;BR /&gt;
if sex eq 'M';&lt;BR /&gt;
n1 = _n_;&lt;BR /&gt;
n2+1;&lt;BR /&gt;
drop sex;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=males;&lt;BR /&gt;
var name n1 n2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Obs    Name       n1    n2&lt;BR /&gt;
  1    Alfred      1     1&lt;BR /&gt;
  2    Henry       5     2&lt;BR /&gt;
  3    James       6     3&lt;BR /&gt;
  4    Jeffrey     9     4&lt;BR /&gt;
  5    John       10     5&lt;BR /&gt;
  6    Philip     15     6&lt;BR /&gt;
  7    Robert     16     7&lt;BR /&gt;
  8    Ronald     17     8&lt;BR /&gt;
  9    Thomas     18     9&lt;BR /&gt;
 10    William    19    10&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
and, to learn a bit more (the difference between WHERE and a subsetting IF) ...&lt;BR /&gt;
&lt;BR /&gt;
data males;&lt;BR /&gt;
set sashelp.class;&lt;BR /&gt;
where sex eq 'M';&lt;BR /&gt;
n1 = _n_;&lt;BR /&gt;
n2+1;&lt;BR /&gt;
drop sex;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=males;&lt;BR /&gt;
var name n1 n2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Obs    Name       n1    n2&lt;BR /&gt;
  1    Alfred      1     1&lt;BR /&gt;
  2    Henry       2     2&lt;BR /&gt;
  3    James       3     3&lt;BR /&gt;
  4    Jeffrey     4     4&lt;BR /&gt;
  5    John        5     5&lt;BR /&gt;
  6    Philip      6     6&lt;BR /&gt;
  7    Robert      7     7&lt;BR /&gt;
  8    Ronald      8     8&lt;BR /&gt;
  9    Thomas      9     9&lt;BR /&gt;
 10    William    10    10&lt;BR /&gt;
&lt;BR /&gt;
so, I'd use the construct ... var + 1;&lt;BR /&gt;
&lt;BR /&gt;
to create a sequence number since is works with both IF and WHERE</description>
      <pubDate>Fri, 14 Jan 2011 03:18:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62160#M13532</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2011-01-14T03:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Sequnce number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62161#M13533</link>
      <description>Hi. Mike&lt;BR /&gt;
Can you explain why it will be appear?&lt;BR /&gt;
It is very interesting.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 14 Jan 2011 07:58:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62161#M13533</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-01-14T07:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Sequnce number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62162#M13534</link>
      <description>hi ... not sure what part of the SAS code the question is about &lt;BR /&gt;
&lt;BR /&gt;
if it's about how to add a sequence number, it's a good way to learn about a lot of&lt;BR /&gt;
stuff that goes on in a data step&lt;BR /&gt;
&lt;BR /&gt;
here's a data step that tries to create 7 sequence numbers&lt;BR /&gt;
if you understand the output, you know (learn ?) a lot &lt;BR /&gt;
&lt;BR /&gt;
data males;&lt;BR /&gt;
retain n4 0 n5 n7;&lt;BR /&gt;
set sashelp.class;&lt;BR /&gt;
if sex eq 'M';&lt;BR /&gt;
n1=_n_;&lt;BR /&gt;
n2+1;&lt;BR /&gt;
n3=n3+1;&lt;BR /&gt;
n4=n4+1;&lt;BR /&gt;
n5=n5+1;&lt;BR /&gt;
n6=sum(n6,1);&lt;BR /&gt;
n7=sum(n7,1);&lt;BR /&gt;
keep n: ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=males;&lt;BR /&gt;
var name n1-n7;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Obs    Name       n1    n2    n3    n4    n5    n6    n7&lt;BR /&gt;
&lt;BR /&gt;
  1    Alfred      1     1     .     1     .     1     1&lt;BR /&gt;
  2    Henry       5     2     .     2     .     1     2&lt;BR /&gt;
  3    James       6     3     .     3     .     1     3&lt;BR /&gt;
  4    Jeffrey     9     4     .     4     .     1     4&lt;BR /&gt;
  5    John       10     5     .     5     .     1     5&lt;BR /&gt;
  6    Philip     15     6     .     6     .     1     6&lt;BR /&gt;
  7    Robert     16     7     .     7     .     1     7&lt;BR /&gt;
  8    Ronald     17     8     .     8     .     1     8&lt;BR /&gt;
  9    Thomas     18     9     .     9     .     1     9&lt;BR /&gt;
 10    William    19    10     .    10     .     1    10&lt;BR /&gt;
&lt;BR /&gt;
n1 / that is based on _n_ , an automatic SAS variable that counts passes through&lt;BR /&gt;
the data step and there are 19 passes since there are 19 observations in data&lt;BR /&gt;
set SASHELP.CLASS ... one feature, these are the original observation numbers&lt;BR /&gt;
from data set SASHELP.CLASS&lt;BR /&gt;
&lt;BR /&gt;
n2 / there are a lot of features here  ... this construct (var + 1) implies two things:  first, the&lt;BR /&gt;
variable is automatically retained (not set to missing each pass back to the top&lt;BR /&gt;
of the data step);  second, the initial value of var is 0 ... so this is like have the statement&lt;BR /&gt;
&lt;BR /&gt;
retain n2 0;&lt;BR /&gt;
&lt;BR /&gt;
in the data step ... but you do not have to write that statement&lt;BR /&gt;
&lt;BR /&gt;
n3 / does not work since the initial value of n3 when that statement is first executed is&lt;BR /&gt;
MISSING and adding anything to a missing value gives a missing result&lt;BR /&gt;
&lt;BR /&gt;
n4 / that works fine:  the initial value of n4 is set to 0 in the retain statement;&lt;BR /&gt;
the value of n4 is retained and not set to missing each pass back to the top of the data step&lt;BR /&gt;
&lt;BR /&gt;
so n4 is the same as n2 ... but using n2+1 instead of n4=n4+1 means that you do not&lt;BR /&gt;
need the retain statement for n2&lt;BR /&gt;
&lt;BR /&gt;
n5 / does not work ... the value of n5 is retained, but the initial value of n5 is missing and&lt;BR /&gt;
if you add anything to a missing value, the result is missing&lt;BR /&gt;
&lt;BR /&gt;
n6 / does not work ... notice that the result is always 1 since functions (SUM) ignore missing&lt;BR /&gt;
values, so when you add 1 to a missing value you get 1 ... but n6 is not retained so it&lt;BR /&gt;
always gets set back to missing at the top of the data step&lt;BR /&gt;
&lt;BR /&gt;
n7/  that works since it uses the SUM function like n6, but the value is retained&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
but ... if your question is about why _n_ works with WHERE and not with IF, just look at the LOG&lt;BR /&gt;
after you run both jobs (one with IF and one with WHERE)&lt;BR /&gt;
&lt;BR /&gt;
the one with IF makes 19 passes through the data step since every observation in SASHELP.CLASS is processed by the SET statement ... the one with WHERE makes 10 passes through the data step since the WHERE statement can be thought of as "peeking" at your data set to see if it actually has to process an observation in the data set ... if the WHERE statement is FALSE, the observation is never "seen" by the SET statement&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
hope all that makes sense</description>
      <pubDate>Fri, 14 Jan 2011 16:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62162#M13534</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2011-01-14T16:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: Sequnce number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62163#M13535</link>
      <description>I do not have a IF/WHERE  but I was using _n_ as below to generate the sequence number.&lt;BR /&gt;
data Class;&lt;BR /&gt;
     length SEQ_NO 8;&lt;BR /&gt;
     set Class;&lt;BR /&gt;
    SEQ_NO = _n_; &lt;BR /&gt;
  run;&lt;BR /&gt;
&lt;BR /&gt;
Do you suggest that I use this instead?&lt;BR /&gt;
length SEQ_NO 8;&lt;BR /&gt;
     set Class;&lt;BR /&gt;
     n1 = _n_;&lt;BR /&gt;
    SEQ_NO = n2+1;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Fri, 14 Jan 2011 18:38:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62163#M13535</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-14T18:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: Sequnce number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62164#M13536</link>
      <description>hi ... no, my suggestion is ...&lt;BR /&gt;
&lt;BR /&gt;
data class;&lt;BR /&gt;
set sashelp.class;&lt;BR /&gt;
SEQ_NO +1 ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
and .. there's no reason for this ...&lt;BR /&gt;
&lt;BR /&gt;
length SEQ_NO 8;&lt;BR /&gt;
&lt;BR /&gt;
the default length of numeric variables in SAS is 8 bytes</description>
      <pubDate>Fri, 14 Jan 2011 19:09:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62164#M13536</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2011-01-14T19:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sequnce number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62165#M13537</link>
      <description>I get 2 errors. How do I fix them?&lt;BR /&gt;
ERROR: File SASHELP.Class.DATA does not exist&lt;BR /&gt;
ERROR: Variable SEQ_NO not found.&lt;BR /&gt;
&lt;BR /&gt;
I am trying to add a sequnce number column to the existing dataset CLASS.</description>
      <pubDate>Fri, 14 Jan 2011 19:41:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62165#M13537</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-14T19:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: Sequnce number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62166#M13538</link>
      <description>hi ... you should post either the EXACT SAS code you used or all of the LOG file (code + messages)&lt;BR /&gt;
&lt;BR /&gt;
otherwise it is difficult to determine why you get error messages&lt;BR /&gt;
&lt;BR /&gt;
but, one thing you can try is ....&lt;BR /&gt;
&lt;BR /&gt;
proc datasets lib=sashelp memtype=data;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
just to see if you have access to the SASHELP library ... the above&lt;BR /&gt;
code should list in the LOG all the datasets in the SASHELP library</description>
      <pubDate>Fri, 14 Jan 2011 19:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62166#M13538</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2011-01-14T19:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: Sequnce number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62167#M13539</link>
      <description>I will try the access to SASHELP part, but do you think this code might produce incorrect sequnce numbers? Because I did run it 5 times and it did not give me an error. &lt;BR /&gt;
data Class;&lt;BR /&gt;
length SEQ_NO 8;&lt;BR /&gt;
set Class;&lt;BR /&gt;
SEQ_NO = _n_; &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
thnaks!</description>
      <pubDate>Fri, 14 Jan 2011 20:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62167#M13539</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-14T20:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sequnce number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62168#M13540</link>
      <description>hi ... yes that works but you are missing the point(s)&lt;BR /&gt;
&lt;BR /&gt;
#1/  _n_ works in that situation, but it does not always work since&lt;BR /&gt;
it counts passes through the data step, not observations added&lt;BR /&gt;
to the data set created in the data step&lt;BR /&gt;
&lt;BR /&gt;
in your SAS job, _n_ works since the number of passes through the &lt;BR /&gt;
data step is the same as the number of observations added to data&lt;BR /&gt;
set class&lt;BR /&gt;
&lt;BR /&gt;
#2/  this ... length SEQ_NO 8; ... is not needed since&lt;BR /&gt;
even without it the length  of SEQ_NO is 8</description>
      <pubDate>Fri, 14 Jan 2011 21:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62168#M13540</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2011-01-14T21:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Sequnce number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62169#M13541</link>
      <description>Hi.&lt;BR /&gt;
I have try your code.There is no secret about it.&lt;BR /&gt;
If you have sorted the sashelp.class then you will get the output like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
Name  Age	Height	Weight	n1	n2&lt;BR /&gt;
Alfred	14	69	112.5     10	1&lt;BR /&gt;
Henry	14	63.5	102.5	11	2&lt;BR /&gt;
James	12	57.3	83	12	3&lt;BR /&gt;
Jeffrey	13	62.5	84	13	4&lt;BR /&gt;
John	        12	59	99.5	14	5&lt;BR /&gt;
Philip	16	72	150	15	6&lt;BR /&gt;
Robert	12	64.8	128	16	7&lt;BR /&gt;
Ronald	15	67	133	17	8&lt;BR /&gt;
Thomas	11	57.5	85	18	9&lt;BR /&gt;
William	15	66.5	112	19	10&lt;BR /&gt;
[/pre]&lt;BR /&gt;
That means when the iterative number is ten (i.e. _n_ = 10) ,output an observation,this time n2+1.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Mon, 17 Jan 2011 04:33:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequnce-number/m-p/62169#M13541</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-01-17T04:33:25Z</dc:date>
    </item>
  </channel>
</rss>

