<?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: uniform(_N_) in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/uniform-N/m-p/509603#M1807</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/243329"&gt;@james_peacock&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In many DATA steps the value of automatic variable _N_ coincides with some observation number. But there are many exceptions to this rule of thumb because in fact _N_ doesn't enumerate observations, but &lt;STRONG&gt;iterations of the DATA step&lt;/STRONG&gt; (see &lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p08a4x7h9mkwqvn16jg3xqwfxful.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;Overview of DATA Step Processing&lt;/A&gt;&amp;nbsp;and for automatic variables in general: &lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0e0mk25gs9binn1s9jiu4otau29.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;Automatic Variables&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some examples (note that PUT statements write to the SAS log by default):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Read 19 observations: _N_ and observation number coincide */

data _null_;
set sashelp.class;
put _n_=;
run;

/* Make 20th DATA step iteration visible */

data _null_;
put _n_=;
set sashelp.class;
run;

/* Read and write 19 obs. within a single iteration of the DATA step: _N_=1 */

data test;
do until(0); /* (no infinite loop thanks to SET statement) */
  set sashelp.class;
  output;
  put _n_=;
end;
run;

/* Create dataset from data lines: _N_=1, 2, 3 */

data a;
input x;
put _n_=;
cards;
10
20
30
;

/* Create same dataset from same data lines, but within
   one iteration of the DATA step: _N_=1 */

data a;
input x;
output;
input x;
output;
input x;
output;
put _n_=;
cards;
10
20
30
;

/* No datasets involved, still _N_=1 */

data _null_;
put _n_=;
run;

/* _N_ can be "mis"used for other purposes (here: as an index variable 
   of a DO loop that is dropped automatically). It's not read-only. */

data squares;
do _n_=1 to 5;
  square=_n_**2;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your example refers to the&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p07gm8ga3268xhn1kcttjk8ctori.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;UNIFORM function&lt;/A&gt;, using &lt;FONT face="courier new,courier"&gt;uniform(_N_)&lt;/FONT&gt; is possibly questionable or misleading (depending on the context) not only because this function is deprecated, but because multiple calls of the function with varying values of _N_ in the same DATA step&amp;nbsp;always use the &lt;EM&gt;same&lt;/EM&gt; seed value.&lt;/P&gt;</description>
    <pubDate>Thu, 01 Nov 2018 16:50:48 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2018-11-01T16:50:48Z</dc:date>
    <item>
      <title>uniform(_N_)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/uniform-N/m-p/509517#M1796</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to SAS and I can't seem to find out what the _N_ represents in the following bit of code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;uniform(_N_)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It doesn't seem to have been defined anywhere within the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;J&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 14:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/uniform-N/m-p/509517#M1796</guid>
      <dc:creator>james_peacock</dc:creator>
      <dc:date>2018-11-01T14:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: uniform(_N_)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/uniform-N/m-p/509526#M1797</link>
      <description>&lt;P&gt;In a datastep, and with some procedures and such like, hidden variables get created at certain points.&amp;nbsp; All documented in the user manual.&amp;nbsp; _n_ is one of those variables and represent logic position of row in the dataset, so first row is 1, second 2 etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 14:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/uniform-N/m-p/509526#M1797</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-01T14:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: uniform(_N_)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/uniform-N/m-p/509527#M1798</link>
      <description>Thank you very much!!</description>
      <pubDate>Thu, 01 Nov 2018 14:18:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/uniform-N/m-p/509527#M1798</guid>
      <dc:creator>james_peacock</dc:creator>
      <dc:date>2018-11-01T14:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: uniform(_N_)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/uniform-N/m-p/509603#M1807</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/243329"&gt;@james_peacock&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In many DATA steps the value of automatic variable _N_ coincides with some observation number. But there are many exceptions to this rule of thumb because in fact _N_ doesn't enumerate observations, but &lt;STRONG&gt;iterations of the DATA step&lt;/STRONG&gt; (see &lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p08a4x7h9mkwqvn16jg3xqwfxful.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;Overview of DATA Step Processing&lt;/A&gt;&amp;nbsp;and for automatic variables in general: &lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0e0mk25gs9binn1s9jiu4otau29.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;Automatic Variables&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some examples (note that PUT statements write to the SAS log by default):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Read 19 observations: _N_ and observation number coincide */

data _null_;
set sashelp.class;
put _n_=;
run;

/* Make 20th DATA step iteration visible */

data _null_;
put _n_=;
set sashelp.class;
run;

/* Read and write 19 obs. within a single iteration of the DATA step: _N_=1 */

data test;
do until(0); /* (no infinite loop thanks to SET statement) */
  set sashelp.class;
  output;
  put _n_=;
end;
run;

/* Create dataset from data lines: _N_=1, 2, 3 */

data a;
input x;
put _n_=;
cards;
10
20
30
;

/* Create same dataset from same data lines, but within
   one iteration of the DATA step: _N_=1 */

data a;
input x;
output;
input x;
output;
input x;
output;
put _n_=;
cards;
10
20
30
;

/* No datasets involved, still _N_=1 */

data _null_;
put _n_=;
run;

/* _N_ can be "mis"used for other purposes (here: as an index variable 
   of a DO loop that is dropped automatically). It's not read-only. */

data squares;
do _n_=1 to 5;
  square=_n_**2;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your example refers to the&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p07gm8ga3268xhn1kcttjk8ctori.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;UNIFORM function&lt;/A&gt;, using &lt;FONT face="courier new,courier"&gt;uniform(_N_)&lt;/FONT&gt; is possibly questionable or misleading (depending on the context) not only because this function is deprecated, but because multiple calls of the function with varying values of _N_ in the same DATA step&amp;nbsp;always use the &lt;EM&gt;same&lt;/EM&gt; seed value.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 16:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/uniform-N/m-p/509603#M1807</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-11-01T16:50:48Z</dc:date>
    </item>
  </channel>
</rss>

