<?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: data step logic iteration with cards in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260080#M50410</link>
    <description>&lt;P&gt;The datastep iteration halts when a SET of INPUT statement reads past the end of file. Any statements before that (in this case a PUT statement) are still executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG title="2016-03-30 15_29_46-Introduction to DATA Step Processing_ How the DATA Step Works_ A Basic Introduct.png" alt="2016-03-30 15_29_46-Introduction to DATA Step Processing_ How the DATA Step Works_ A Basic Introduct.png" src="https://communities.sas.com/t5/image/serverpage/image-id/2560iD5E5DDBB20B30262/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that your output dataset still has only one observation with X=1 and Y=2, as expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Mar 2016 13:31:54 GMT</pubDate>
    <dc:creator>jklaverstijn</dc:creator>
    <dc:date>2016-03-30T13:31:54Z</dc:date>
    <item>
      <title>data step logic iteration with cards</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260047#M50400</link>
      <description>&lt;P&gt;Hi !&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to understand the logic behind this simple data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test ;
   put _all_ ;
   input x ;
   y = 2 * x ;
cards ;
1
;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the log it is displayed :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x=. y=. _n_=1&lt;/P&gt;
&lt;P&gt;x=. y=. _n_=2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I probably "missing" few details :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Why are there 2 iteration ?&lt;/P&gt;
&lt;P&gt;2. Is the first iteration done &amp;nbsp;for reading the data descriptor ?&lt;/P&gt;
&lt;P&gt;3. Why then at the second iteration (when reading INPUT i guess ) X and Y are still missing ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;saskap&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2016 12:33:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260047#M50400</guid>
      <dc:creator>saskapa</dc:creator>
      <dc:date>2016-03-30T12:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: data step logic iteration with cards</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260050#M50401</link>
      <description>&lt;P&gt;What you see is because the put _all_ statement is before the input. The datastep halts when the input statement reads end of data in the cards. That's only after you print _all_ to the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, because the put statement comes before any other statements all variables are missing. At the start of an iteration the PDV is cleared for all non-retained variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For illustration you could move the put statement to the botrtom of the datastep after the assigment tof Y.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this clariefies things a bit.&lt;/P&gt;
&lt;P&gt;- Jan&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2016 12:38:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260050#M50401</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-03-30T12:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: data step logic iteration with cards</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260053#M50403</link>
      <description>&lt;P&gt;For the basics have a good look at &lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001290590.htm" target="_self"&gt;How the DATA Step Works: A Basic Introduction&lt;/A&gt;. It is essential learning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2016 12:41:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260053#M50403</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-03-30T12:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: data step logic iteration with cards</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260071#M50407</link>
      <description>&lt;P&gt;Thanks Jan...Yes off course the reinitialisation of the PDV...! &amp;nbsp; However, why two iteration ? My only explanation would be that the first iteration creates&amp;nbsp;&amp;nbsp;data descripor (compilation section and _n_=1) &amp;nbsp;and that the second iteration only it starts the execution...What do you think ?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2016 13:24:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260071#M50407</guid>
      <dc:creator>saskapa</dc:creator>
      <dc:date>2016-03-30T13:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: data step logic iteration with cards</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260080#M50410</link>
      <description>&lt;P&gt;The datastep iteration halts when a SET of INPUT statement reads past the end of file. Any statements before that (in this case a PUT statement) are still executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG title="2016-03-30 15_29_46-Introduction to DATA Step Processing_ How the DATA Step Works_ A Basic Introduct.png" alt="2016-03-30 15_29_46-Introduction to DATA Step Processing_ How the DATA Step Works_ A Basic Introduct.png" src="https://communities.sas.com/t5/image/serverpage/image-id/2560iD5E5DDBB20B30262/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that your output dataset still has only one observation with X=1 and Y=2, as expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2016 13:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260080#M50410</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-03-30T13:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: data step logic iteration with cards</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260082#M50412</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8584"&gt;@saskapa&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Jan...Yes off course the reinitialisation of the PDV...! &amp;nbsp; However, why two iteration ? My only explanation would be that the first iteration creates&amp;nbsp;&amp;nbsp;data descripor (compilation section and _n_=1) &amp;nbsp;and that the second iteration only it starts the execution...What do you think ?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No. &amp;nbsp;All data steps are compiled before they start. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason there are two put statements is because the implied&amp;nbsp;data step loop runs twice. &amp;nbsp;The second time it stops when the INPUT statement reads past the end of the input. &amp;nbsp;So it never gets to the end where the record is written so you only have one output record. This is how all simple data steps work. &amp;nbsp;The same would happen if you were using a SET statement instead of reading raw data with an INPUT statement. When the SET statement reads past the end of the data then the step stops.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2016 13:39:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260082#M50412</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-03-30T13:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: data step logic iteration with cards</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260085#M50415</link>
      <description>&lt;P&gt;Thanks Tom for the clarification&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2016 13:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-logic-iteration-with-cards/m-p/260085#M50415</guid>
      <dc:creator>saskapa</dc:creator>
      <dc:date>2016-03-30T13:54:32Z</dc:date>
    </item>
  </channel>
</rss>

