<?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: I don't understand when statements are compile time. in Programming 1 and 2</title>
    <link>https://communities.sas.com/t5/Programming-1-and-2/I-don-t-understand-when-statements-are-compile-time/m-p/795220#M1035</link>
    <description>&lt;P&gt;The distinction is more about statements like DROP/KEEP/RENAME and FORMAT/INFORMAT/LABEL/ATTRIB/LENGTH that just help determine the structure of the data and not the content.&amp;nbsp; You cannot run them conditionally by using branching logic like IF/THEN/ELSE/DO/GOTO etc. since there is no actual code that runs for every iteration of the data step.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure if you would consider WHERE as something that is strictly "compile" time.&amp;nbsp; But it is external to the execution of the actual data step code as it determines which observations are provided to the data step when it actually runs.&amp;nbsp; So there is no way to run it conditionally.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to run code you have generated dynamically (like the eval() function you cited) then use the macro language to generate the code.&amp;nbsp; You can execute a macro that generates code. Or just expand the value of a macro variable you have created with code in it.&amp;nbsp; Or write the code to a file and use the macro language statement %INCLUDE to run the code as if it was part of the original program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Feb 2022 16:58:59 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-02-09T16:58:59Z</dc:date>
    <item>
      <title>I don't understand when statements are compile time.</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/I-don-t-understand-when-statements-are-compile-time/m-p/795198#M1034</link>
      <description>&lt;P&gt;A quote from course programming 2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;The KEEP, WHERE, and FORMAT statements are compile-time only.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I don't understand why those are compile-time. WHERE takes a condition which is true or false depending on the row from the input data. It can't be evaluated at compile-time. What is compiled then?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trying to understand the logic, if a compile-time statement can have an effect depending on the actual data, then why aren't all statements compile-time? For example, you can do if-else-constructions. Does SAS parse the English words "if" and "else" every time? (If the code is not compiled that's what I expect.) It makes more sense to me to compile those if-else-constructions, and really every statement, to something lower level before execution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know there are languages that are interpreted like javascript where an eval function exists. I wonder how SAS compares to that or if it's something completely different.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 15:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/I-don-t-understand-when-statements-are-compile-time/m-p/795198#M1034</guid>
      <dc:creator>carapaxit</dc:creator>
      <dc:date>2022-02-09T15:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: I don't understand when statements are compile time.</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/I-don-t-understand-when-statements-are-compile-time/m-p/795220#M1035</link>
      <description>&lt;P&gt;The distinction is more about statements like DROP/KEEP/RENAME and FORMAT/INFORMAT/LABEL/ATTRIB/LENGTH that just help determine the structure of the data and not the content.&amp;nbsp; You cannot run them conditionally by using branching logic like IF/THEN/ELSE/DO/GOTO etc. since there is no actual code that runs for every iteration of the data step.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure if you would consider WHERE as something that is strictly "compile" time.&amp;nbsp; But it is external to the execution of the actual data step code as it determines which observations are provided to the data step when it actually runs.&amp;nbsp; So there is no way to run it conditionally.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to run code you have generated dynamically (like the eval() function you cited) then use the macro language to generate the code.&amp;nbsp; You can execute a macro that generates code. Or just expand the value of a macro variable you have created with code in it.&amp;nbsp; Or write the code to a file and use the macro language statement %INCLUDE to run the code as if it was part of the original program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 16:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/I-don-t-understand-when-statements-are-compile-time/m-p/795220#M1035</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-09T16:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: I don't understand when statements are compile time.</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/I-don-t-understand-when-statements-are-compile-time/m-p/795242#M1036</link>
      <description>&lt;P&gt;Thank you. That makes it more clear. A compile-time statement can't be run conditionally. I just tried this as an experiment (edited version of p201p05):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data monument(drop=ParkType) park(drop=ParkType) other;
	set pg2.np_yearlytraffic;
	if ParkType = 'National Monument' then output monument;
	else if ParkType = 'National Park' then output park;
	else output other;
	
	if ParkType='does not exist' then do;
		drop Location;
	end;
	
	drop Region;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The column Location is dropped even though the condition is never true. It looks like SAS scans the data step for compile-time statements and applies them first, just like conditional column declarations (that I have seen earlier in the course). In the same way it should be impossible to change the WHERE condition while processing rows.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 17:30:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/I-don-t-understand-when-statements-are-compile-time/m-p/795242#M1036</guid>
      <dc:creator>carapaxit</dc:creator>
      <dc:date>2022-02-09T17:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: I don't understand when statements are compile time.</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/I-don-t-understand-when-statements-are-compile-time/m-p/795259#M1037</link>
      <description>&lt;P&gt;The WHERE statement can be regarded as "compile time" because WHERE (unlike IF) outsources the filtering to the data engine.&amp;nbsp; That engine might be a sas dataset engine, or (say) a foreign engine, but the logic of the filter is entirely outside of the DATA step statements.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Among other consequences, this means&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;In the data step, the observations that fail the filter are never assigned an _N_ value.&amp;nbsp; I.e. they are not counted as observations processed.&amp;nbsp; &amp;nbsp;The same filtering logic in an IF statement does count those obs.&amp;nbsp; Just try processing SASHELP.CLASS, once with WHERE SEX='F', and once with IF SEX='F';&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;The WHERE statement can be used with any other PROC.&amp;nbsp; The IF statement can't.&amp;nbsp; Great if you want to run, say, a regression on a particular subset of data - no need for a DATA step prior to the PROC REG.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So while KEEP and DROP can be thought of as compile time because they clearly don't impact the programming logic, the WHERE is a bit more active, but is still not part of the DATA step logic.&amp;nbsp; It is not "compiled" into the underlying DATA step code.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 18:05:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/I-don-t-understand-when-statements-are-compile-time/m-p/795259#M1037</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-02-09T18:05:20Z</dc:date>
    </item>
  </channel>
</rss>

