<?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 Why the variable being dropped still being used to calculate in the same datastep? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-the-variable-being-dropped-still-being-used-to-calculate-in/m-p/730857#M227640</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a code below, I am wondering why the StormLength still being calculated while the EndDate being dropped by the drop statement in advance?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data storm_complete;
	set pg2.storm_summary_small; 
	length Ocean $ 8;
	&lt;STRONG&gt;drop EndDate;&lt;/STRONG&gt;
	where Name is not missing;
	Basin=upcase(Basin);
	&lt;STRONG&gt;StormLength=EndDate-StartDate;&lt;/STRONG&gt;
	if substr(Basin,2,1)="I" then Ocean="Indian";
	else if substr(Basin,2,1)="A" then Ocean="Atlantic";
	else Ocean="Pacific";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The answer from the instructor is not clear to me, I do not know why values have been generated for StormLength. My standpoint is: while the datastep running, it will run from the first statement to the last statement to finish one loop and continue the next loop from the data statement. So, logically speaking, while the drop statement coming before the computing equation of StormLength, there should be no result for StormLength from my opinion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ResoluteCarbon_0-1617310954570.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56823i2062041B0538A6F9/image-size/large?v=v2&amp;amp;px=999" role="button" title="ResoluteCarbon_0-1617310954570.png" alt="ResoluteCarbon_0-1617310954570.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
    <pubDate>Thu, 01 Apr 2021 21:06:09 GMT</pubDate>
    <dc:creator>ResoluteCarbon</dc:creator>
    <dc:date>2021-04-01T21:06:09Z</dc:date>
    <item>
      <title>Why the variable being dropped still being used to calculate in the same datastep?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-variable-being-dropped-still-being-used-to-calculate-in/m-p/730857#M227640</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a code below, I am wondering why the StormLength still being calculated while the EndDate being dropped by the drop statement in advance?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data storm_complete;
	set pg2.storm_summary_small; 
	length Ocean $ 8;
	&lt;STRONG&gt;drop EndDate;&lt;/STRONG&gt;
	where Name is not missing;
	Basin=upcase(Basin);
	&lt;STRONG&gt;StormLength=EndDate-StartDate;&lt;/STRONG&gt;
	if substr(Basin,2,1)="I" then Ocean="Indian";
	else if substr(Basin,2,1)="A" then Ocean="Atlantic";
	else Ocean="Pacific";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The answer from the instructor is not clear to me, I do not know why values have been generated for StormLength. My standpoint is: while the datastep running, it will run from the first statement to the last statement to finish one loop and continue the next loop from the data statement. So, logically speaking, while the drop statement coming before the computing equation of StormLength, there should be no result for StormLength from my opinion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ResoluteCarbon_0-1617310954570.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56823i2062041B0538A6F9/image-size/large?v=v2&amp;amp;px=999" role="button" title="ResoluteCarbon_0-1617310954570.png" alt="ResoluteCarbon_0-1617310954570.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 21:06:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-variable-being-dropped-still-being-used-to-calculate-in/m-p/730857#M227640</guid>
      <dc:creator>ResoluteCarbon</dc:creator>
      <dc:date>2021-04-01T21:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: Why the variable being dropped still being used to calculate in the same datastep?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-variable-being-dropped-still-being-used-to-calculate-in/m-p/730858#M227641</link>
      <description>&lt;P&gt;The DROP statement only excludes the variable from being &lt;EM&gt;written&lt;/EM&gt; to the output, but it stays present in the PDV and can be used in calculations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And since the DROP statement is a declarative statement, its position in the code is irrelevant.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 21:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-variable-being-dropped-still-being-used-to-calculate-in/m-p/730858#M227641</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-01T21:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Why the variable being dropped still being used to calculate in the same datastep?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-variable-being-dropped-still-being-used-to-calculate-in/m-p/730859#M227642</link>
      <description>&lt;P&gt;They did not provide very good explanation.&lt;/P&gt;
&lt;P&gt;Your understanding is right, but you are missing something.&amp;nbsp; Not all statements are "executable".&amp;nbsp; That is they don't actually take any action when the data step is running. Instead they just help determine how the data step will run.&amp;nbsp; The DROP statement just means that the variable is not included in the data written to the output dataset.&amp;nbsp; The fact that variable is not written out has no impact on the values the variable can have while the data step is executing. Since the DROP statement has no executable component it does not matter where in the data step it appears.&amp;nbsp; Personally I normally put the DROP statement at the bottom of the step as it makes more sense to me there.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 21:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-variable-being-dropped-still-being-used-to-calculate-in/m-p/730859#M227642</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-01T21:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Why the variable being dropped still being used to calculate in the same datastep?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-variable-being-dropped-still-being-used-to-calculate-in/m-p/730860#M227643</link>
      <description>This is the mistake: it will run from the first statement to the last statement to finish one loop and continue the next loop from the data statement&lt;BR /&gt;&lt;BR /&gt;This is not 100% true, it's a simplification used when you start programming. &lt;BR /&gt;&lt;BR /&gt;KEEP, DROP, WHERE, BY are a few examples that can go in several places without needing to necessarily be in the correct order. Some PROCs will complain if BY isn't before some statements and others won't which can also be annoying. &lt;BR /&gt;&lt;BR /&gt;FYI you can test your assumptions. A good way to do that is to use PUT statements. So if you added a PUT _all_ ; statement to your code (after SET &amp;amp; before RUN are good places) it would put all variables and their values, which would let you see what is happening 'behind the scenes'. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Apr 2021 21:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-variable-being-dropped-still-being-used-to-calculate-in/m-p/730860#M227643</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-01T21:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Why the variable being dropped still being used to calculate in the same datastep?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-variable-being-dropped-still-being-used-to-calculate-in/m-p/730874#M227647</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your tips,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just found another way to see what happened behind the scene is to use the debugger button in SAS EG to see what inside the PDV after each excutable statement or each data iteration.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ResoluteCarbon_0-1617316043387.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56827i9854085CD1C51DAE/image-size/large?v=v2&amp;amp;px=999" role="button" title="ResoluteCarbon_0-1617316043387.png" alt="ResoluteCarbon_0-1617316043387.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 22:28:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-variable-being-dropped-still-being-used-to-calculate-in/m-p/730874#M227647</guid>
      <dc:creator>ResoluteCarbon</dc:creator>
      <dc:date>2021-04-01T22:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why the variable being dropped still being used to calculate in the same datastep?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-variable-being-dropped-still-being-used-to-calculate-in/m-p/731377#M227821</link>
      <description>Yeah, but the PUT statement is a technique that works in all languages and platforms &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;</description>
      <pubDate>Mon, 05 Apr 2021 15:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-variable-being-dropped-still-being-used-to-calculate-in/m-p/731377#M227821</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-05T15:07:37Z</dc:date>
    </item>
  </channel>
</rss>

