<?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 is the purpose of if _N_=1 then do in this data step? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46466#M9587</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Ok, notice this line in your code:&lt;/P&gt;&lt;P&gt;set sasuser.contrib;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The number of loop is the total number of&amp;nbsp; obs in 'sasuser.contrib' plus 1. It comes from the implicit loop of 'set'. Unless you stop(abort) or skip the loop somewhere in your downstream code, it will be n+1, n being the number of obs in 'sasuser.contrib'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Having said that, it would be somehow different if you apply DOW on&amp;nbsp; 'set' statement, such as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; do until (your conditions);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set sasuser.contrib;&lt;/P&gt;&lt;P&gt;blah blah;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then the number of the loop will be the number of DOW plus 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: if you remove _n_ line, you will NOT see errors if your original code has no error. You will see bunch of notes telling your hash object has been initiated, then couple of lines later, initiated again, and again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 28 Mar 2012 14:30:49 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2012-03-28T14:30:49Z</dc:date>
    <item>
      <title>what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46460#M9581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;in advanced certification prep, book&amp;nbsp; in hash table chapter, it has following data step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone help me understand what exactly does "if _N_=1 then do" do?&lt;/P&gt;&lt;P&gt;I really don't see the need of using this statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work.difference (drop= goalamount);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length goalamount 8;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _N_ = 1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash goal( );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; goal.definekey("QtrNum");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; goal.definedata("GoalAmount");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; goal.definedone( );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(qtrnum, goalamount);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; goal.add(key:’qtr1’, data:10 );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; goal.add(key:’qtr2’, data:15 );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; goal.add(key:’qtr3’, data: 5 );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; goal.add(key:’qtr4’, data:15 );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set sasuser.contrib;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; goal.find();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Diff = amount - goalamount;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 05:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46460#M9581</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2012-03-28T05:39:45Z</dc:date>
    </item>
    <item>
      <title>what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46461#M9582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Hi ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This says that if the step is reading the first observation in datastep then hash variable is decalred and properties are set including the key variabels and data variables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 06:04:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46461#M9582</guid>
      <dc:creator>manojinpec</dc:creator>
      <dc:date>2012-03-28T06:04:31Z</dc:date>
    </item>
    <item>
      <title>what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46462#M9583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;can I remove this line? what effect will it have without this line then?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 07:04:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46462#M9583</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2012-03-28T07:04:51Z</dc:date>
    </item>
    <item>
      <title>what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46463#M9584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You must keep it. If you remove it.&lt;/P&gt;&lt;P&gt;At every data loop, SAS will re-build this hash table, this is not what you need.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 07:20:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46463#M9584</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-03-28T07:20:16Z</dc:date>
    </item>
    <item>
      <title>what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46464#M9585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try removing it, and then compare your log, you will see what Ksharp means.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 11:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46464#M9585</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-03-28T11:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46465#M9586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ksharp, you said: "At every data loop, SAS will re-build this hash table"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do not understand, where does the loop come from?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I removed the line, nothing happened, I still do not see the magic of this line here.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 14:20:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46465#M9586</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2012-03-28T14:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46466#M9587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Ok, notice this line in your code:&lt;/P&gt;&lt;P&gt;set sasuser.contrib;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The number of loop is the total number of&amp;nbsp; obs in 'sasuser.contrib' plus 1. It comes from the implicit loop of 'set'. Unless you stop(abort) or skip the loop somewhere in your downstream code, it will be n+1, n being the number of obs in 'sasuser.contrib'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Having said that, it would be somehow different if you apply DOW on&amp;nbsp; 'set' statement, such as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; do until (your conditions);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set sasuser.contrib;&lt;/P&gt;&lt;P&gt;blah blah;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then the number of the loop will be the number of DOW plus 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: if you remove _n_ line, you will NOT see errors if your original code has no error. You will see bunch of notes telling your hash object has been initiated, then couple of lines later, initiated again, and again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 14:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46466#M9587</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-03-28T14:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46467#M9588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hai.kuo: Not on 9.2!&amp;nbsp; Thus, it is a good question.&amp;nbsp; The result looks like it will stay the same but, without the if statement, the processing time will increase dramatically.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 15:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46467#M9588</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-03-28T15:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46468#M9589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I see, Art. Probably that is why OP is so confused. Thanks for pointing it out! Learned!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In addition to increased processing time, without first _n_ loop, it won't work if hash() need to be dynanmically&amp;nbsp; modified during the course.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 15:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46468#M9589</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-03-28T15:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46469#M9590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;still try to understand this _N_ better, so what what contains _N_=1?&lt;/P&gt;&lt;P&gt;In addition, under _N_=1, it only loop once, is that it?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 23:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46469#M9590</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2012-03-28T23:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46470#M9591</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are preparing for the certification exam, you will probably want to read (at least):&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001290590.htm"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001290590.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Mar 2012 01:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46470#M9591</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-03-29T01:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46471#M9592</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you for pointing me the interesting link, but I am more focused on understanding the logic of the code behind it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Mar 2012 03:57:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46471#M9592</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2012-03-29T03:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46472#M9593</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;_N_ is an automatic SAS counter that can be used to find out how many times the DATA step has looped.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The purpose for it in your example is to only create and load the hash table once, at the start of the first loop through the step. It only needs to be done once.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you removed this check the hash table would be created and loaded for every record the step is processing!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Mar 2012 05:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46472#M9593</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2012-03-29T05:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46473#M9594</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;P&gt;ZRick wrote:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp, you said: "At every data loop, SAS will re-build this hash table"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do not understand, where does the loop come from?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I removed the line, nothing happened, I still do not see the magic of this line here.&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ZRick,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You make a comment like this which leads one to believe you do not understand how a data step works. So Art provided a link that exactly shows how a data step loops and where _n_ comes from, but you totally dismissed his help. Take 5 minutes to read the link, then maybe you will understand where the looping occurs and why. From that point, maybe you will get insight into why the hash object only needs to be declared and populated once when _n_ = 1.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Mar 2012 11:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46473#M9594</guid>
      <dc:creator>FloydNevseta</dc:creator>
      <dc:date>2012-03-29T11:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46474#M9595</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;"The purpose for it in your example is to only create and load the hash table once, at the start of the first loop through the step. It only needs to be done once." &lt;/P&gt;&lt;P&gt;Agreed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"If you removed this check the hash table would be created and loaded for every record the step is processing!"&lt;/P&gt;&lt;P&gt;Hmmmm, not always. It depends heavily on your data step construct. There are constructs within which loops just once but output multiple records(eg. output()), or loops a lot less than the records it outputs or processes, eg. wrap up 'set' statement with DOW.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So to use _n_=1 loop is more of a better practice and saft guard issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Mar 2012 11:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46474#M9595</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-03-29T11:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46475#M9596</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Cheers Haikuo. My comments were based just on the code as it stands. Of course if you change it with your own looping code then you could avoid loading the hash table for every record by another method. Just trying to keep it simple!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Mar 2012 20:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46475#M9596</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2012-03-29T20:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46476#M9597</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi SASkiwi,&lt;/P&gt;&lt;P&gt;There is NOT a second that I have questioned your or others' understanding of Hash. However, Given that OP is obviously new to Hash, I choose this&amp;nbsp; complex way to unfold more aspects in front him/her. It seems more purplex up front, but hopefully will help him with the big picture further down the road.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Mar 2012 22:29:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46476#M9597</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-03-29T22:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: what is the purpose of if _N_=1 then do in this data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46477#M9598</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One way to think about how SAS processes a data step is to consider a simple step to calculate a new variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set old;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; y= x*x ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now if there are 100 observations in OLD then SAS must execute the assignment statement that creates Y 100 times.&amp;nbsp; So the implied loop over all input data is what lets that happen.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This concept is one of the things that makes creating SAS programs so much simplier than the old FORTRAN or PL/I programs we had to use before SAS was developed. Or for that matter more modern languages such as Java or Excel.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Mar 2012 22:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-purpose-of-if-N-1-then-do-in-this-data-step/m-p/46477#M9598</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-03-29T22:37:58Z</dc:date>
    </item>
  </channel>
</rss>

