<?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: Open and closed intervals in the if statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28595#M5278</link>
    <description>It's now clear that your code is not working yet.  You have a reference to an array in the statement below which is illegal:&lt;BR /&gt;
&lt;BR /&gt;
if conditions ne "" then &lt;BR /&gt;
&lt;BR /&gt;
I expect you will see this error, given the pasted code syntax:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
ERROR: Illegal reference to the array conditions.&lt;BR /&gt;
&lt;BR /&gt;
Suggest you get your code working as a static program, then consider some alternative "more flexible?" methods (possibly more simply using macro logic).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: sbb

Message was edited by: sbb</description>
    <pubDate>Thu, 04 Nov 2010 18:19:15 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2010-11-04T18:19:15Z</dc:date>
    <item>
      <title>Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28585#M5268</link>
      <description>Is there a way to use open and/or closed numeric non-integer intervals with the IF statement?&lt;BR /&gt;
&lt;BR /&gt;
e.g. X=1.26;&lt;BR /&gt;
if X in (1:5) then Y=1; else Y=0; results in Y=0.&lt;BR /&gt;
if X in (1.1:5.3) then Y=1; else Y=0; returns an error.&lt;BR /&gt;
&lt;BR /&gt;
For programming reasons I can't use the syntax &lt;BR /&gt;
if X &amp;gt;= 1 and X&amp;lt;=5 then Y=1; else Y=0;&lt;BR /&gt;
as I need a single condition to follow the variable X without repeating the variable name.&lt;BR /&gt;
&lt;BR /&gt;
I note that one can use the BETWEEN operator with a WHERE statement but not with an IF statement - does anyone know the rationale behind this?</description>
      <pubDate>Thu, 04 Nov 2010 09:24:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28585#M5268</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-11-04T09:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28586#M5269</link>
      <description>It is not clear to me what values you expect from the range 1.1:5.3&lt;BR /&gt;
What is the increment?&lt;BR /&gt;
&lt;BR /&gt;
You can create an array of target values and use the IN operator on the array.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
1259  data _null_;&lt;BR /&gt;
1260     array x[5];&lt;BR /&gt;
1261     j = 1;&lt;BR /&gt;
1262     do a=1.1 by 1 while(j le dim(x));&lt;BR /&gt;
1263        x&lt;J&gt; = a;&lt;BR /&gt;
1264        j + 1;&lt;BR /&gt;
1265        end;&lt;BR /&gt;
1266     put x&lt;LI&gt;;&lt;BR /&gt;
1267     z = 2.1;&lt;BR /&gt;
1268     z_in_x = z in x;&lt;BR /&gt;
1269     put z_in_x=;&lt;BR /&gt;
1270     run;&lt;BR /&gt;
&lt;BR /&gt;
1.1 2.1 3.1 4.1 5.1&lt;BR /&gt;
z_in_x=1&lt;BR /&gt;
[/pre]&lt;/LI&gt;&lt;/J&gt;</description>
      <pubDate>Thu, 04 Nov 2010 12:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28586#M5269</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-11-04T12:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28587#M5270</link>
      <description>Hi, actually what I am looking for is the equivalent of the BETWEEN operator for the IF statement (for some reason BETWEEN can only be used with the WHERE statement). i.e. "IF X in range then do Y", where X is a non-integer numeric variable. My code can't use the syntax "IF X ge z1 and x le z2 then do Y", as there must be only a single condition following the variable X.</description>
      <pubDate>Thu, 04 Nov 2010 13:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28587#M5270</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-11-04T13:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28588#M5271</link>
      <description>Consider this "expression" structure:&lt;BR /&gt;
&lt;BR /&gt;
IF ( 0.5 LE &lt;YOUR_VARIABLE&gt; LE 1.5 ) then....;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
sas language data step if statement expression site:sas.com&lt;/YOUR_VARIABLE&gt;</description>
      <pubDate>Thu, 04 Nov 2010 14:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28588#M5271</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-04T14:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28589#M5272</link>
      <description>Thanks, I am looking for a condition that FOLLOWS the variable only as I am doing a lookup of a table that contains only the part after the variable. i.e. I am looking for "IF X &lt;CONDITION&gt; then ...", where &lt;CONDITION&gt; is kept in the lookup table. E.g. &lt;CONDITION&gt; is &lt;BETWEEN 1.3="" and="" 10.7=""&gt;, except you can't use BETWEEN with the IF statement.&lt;/BETWEEN&gt;&lt;/CONDITION&gt;&lt;/CONDITION&gt;&lt;/CONDITION&gt;</description>
      <pubDate>Thu, 04 Nov 2010 14:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28589#M5272</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-11-04T14:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28590#M5273</link>
      <description>Why do have such silly rules.&lt;BR /&gt;
&lt;BR /&gt;
Perhaps this will meet the requirement.  Check the bounds in different if statements.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
1487  data _null_;&lt;BR /&gt;
1488     do x = 0.26 to 7.26 by 1;&lt;BR /&gt;
1489        put 'NOTE: ' x=;&lt;BR /&gt;
1490        if x ge 1.1 then if x le 5.3&lt;BR /&gt;
1491           then put 'NOTE- ' x= 'is in the range 1.1 to 5.3';&lt;BR /&gt;
1492        end;&lt;BR /&gt;
1493     run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: x=0.26&lt;BR /&gt;
NOTE: x=1.26&lt;BR /&gt;
      x=1.26 is in the range 1.1 to 5.3&lt;BR /&gt;
NOTE: x=2.26&lt;BR /&gt;
      x=2.26 is in the range 1.1 to 5.3&lt;BR /&gt;
NOTE: x=3.26&lt;BR /&gt;
      x=3.26 is in the range 1.1 to 5.3&lt;BR /&gt;
NOTE: x=4.26&lt;BR /&gt;
      x=4.26 is in the range 1.1 to 5.3&lt;BR /&gt;
NOTE: x=5.26&lt;BR /&gt;
      x=5.26 is in the range 1.1 to 5.3&lt;BR /&gt;
NOTE: x=6.26&lt;BR /&gt;
NOTE: x=7.26&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 04 Nov 2010 14:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28590#M5273</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-11-04T14:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28591#M5274</link>
      <description>To the OP:  did the IF example not make sense?  Suggest you try it to test a value range.  Otherwise explain why you don't think it will work (but without just repeating the question/post again).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 04 Nov 2010 16:24:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28591#M5274</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-04T16:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28592#M5275</link>
      <description>&amp;gt; Thanks, I am looking for a condition that FOLLOWS the&lt;BR /&gt;
&amp;gt; variable only as I am doing a lookup of a table that&lt;BR /&gt;
&amp;gt; contains only the part after the variable. i.e. I am&lt;BR /&gt;
&amp;gt; looking for "IF X &lt;CONDITION&gt; then ...", where&lt;BR /&gt;
&amp;gt; &lt;CONDITION&gt; is kept in the lookup table. E.g.&lt;BR /&gt;
&amp;gt; &lt;CONDITION&gt; is &lt;BETWEEN 1.3="" and="" 10.7=""&gt;, except you&lt;BR /&gt;
&amp;gt; can't use BETWEEN with the IF statement.&lt;BR /&gt;
...&lt;BR /&gt;
If the &lt;CONDITION&gt; can contain the name of the variable (which will likely be the case when the lookup key is indeed the variable name), then you can do something like below. That is the &lt;CONDITION&gt; part being:&lt;BR /&gt;
[pre]&lt;BR /&gt;
    = ifn(x=0|missing(x), 999, ifn(1.3&amp;lt;=x&amp;lt;=10.7,x,-x))&lt;BR /&gt;
[/pre]&lt;BR /&gt;
hope this helps a bit.&lt;BR /&gt;
[pre]&lt;BR /&gt;
   data _null_;&lt;BR /&gt;
     do x = ., 0, 1.26, 6.26, 10.71;&lt;BR /&gt;
       if x = ifn(x=0|missing(x), 999, ifn(1.3&amp;lt;=x&amp;lt;=10.7,x,-x)) then y = 1;&lt;BR /&gt;
       else y = 0;&lt;BR /&gt;
       put x= y=;&lt;BR /&gt;
     end;&lt;BR /&gt;
   run;&lt;BR /&gt;
   /* on log&lt;BR /&gt;
   x=. y=0&lt;BR /&gt;
   x=0 y=0&lt;BR /&gt;
   x=1.26 y=0&lt;BR /&gt;
   x=6.26 y=1&lt;BR /&gt;
   x=10.71 y=0&lt;BR /&gt;
   */&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Wait a minute. If you are *not* allowed to do a &lt;CONDITION&gt; like:&lt;BR /&gt;
[pre]&lt;BR /&gt;
   &amp;gt;= 1.3 and x &amp;lt;= 10.7&lt;BR /&gt;
[/pre]&lt;BR /&gt;
then, there is no hope. This cannot be done, as far as I know, that is.&lt;/CONDITION&gt;&lt;/CONDITION&gt;&lt;/CONDITION&gt;&lt;/BETWEEN&gt;&lt;/CONDITION&gt;&lt;/CONDITION&gt;&lt;/CONDITION&gt;</description>
      <pubDate>Thu, 04 Nov 2010 17:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28592#M5275</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2010-11-04T17:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28593#M5276</link>
      <description>Exactly how are you doing the "lookup table" invocation at SAS compilation time - that would be an interesting point to clarify?  Also, please share the exact SAS code you are executing, preferably in a SAS -generated log, not just your pasted code-piece.  Clearly your original post isn't quite consistent with whatever is being attempted to resolve "on the fly" a piece of your IF statement.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 04 Nov 2010 18:05:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28593#M5276</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-04T18:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28594#M5277</link>
      <description>Here is what I am trying to do. I have a lookup table of conditions for each outcome (work.test in this illustration, except much bigger in practice) and then I use a data step to generate all the SAS code required and put it into a macro variable 'all_code'. The coding is much simpler if all &lt;CONDITION&gt; are 'to the right' of the outcome variable only:&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
  length outvar condition1 condition2 condition3 condition4 $20;&lt;BR /&gt;
  outvar = "outvar1"; condition1="ge 20"; condition2="eq 1"; condition3="ne 5"; condition4=""; output;&lt;BR /&gt;
  outvar = "outvar2"; condition1=""; condition2=""; condition3="lt 20 "; condition4="eq 1"; output;&lt;BR /&gt;
  outvar = "outvar3"; condition1=""; condition2="eq 1"; condition3="gt 20 "; condition4="eq 1"; output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data _null_in_practice;&lt;BR /&gt;
  length _t $300;&lt;BR /&gt;
  retain _t condition_names1 - condition_names4;&lt;BR /&gt;
  array conditions{*} $20 condition1 - condition4;&lt;BR /&gt;
  array condition_names{1:4} $20 ("condition1" "condition2" "condition3" "condition4");&lt;BR /&gt;
  set test end=last;&lt;BR /&gt;
  if _n_ = 1 then _t="";&lt;BR /&gt;
  do i = 1 to dim(conditions);&lt;BR /&gt;
    if i=1 then _t=trim(left(_t))!!" if ";&lt;BR /&gt;
    if conditions&lt;I&gt; ne "" then&lt;BR /&gt;
     _t = trim(left(_t))!!" ("!!trim(left(condition_names&lt;I&gt;))!!" "&lt;BR /&gt;
     !!trim(left(conditions&lt;I&gt;))!!") and";&lt;BR /&gt;
    if i = dim(conditions) then do;&lt;BR /&gt;
      _t = substr(_t,1,length(_t) - 3)!!" then "!! trim(left(outvar)) !!" = 1; else " &lt;BR /&gt;
      !! trim(left(outvar)) !! " = 0;";&lt;BR /&gt;
    end;&lt;BR /&gt;
  end;&lt;BR /&gt;
  if last then call symput('all_code',trim(left(_t)));&lt;BR /&gt;
run;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/CONDITION&gt;</description>
      <pubDate>Thu, 04 Nov 2010 18:12:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28594#M5277</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-11-04T18:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28595#M5278</link>
      <description>It's now clear that your code is not working yet.  You have a reference to an array in the statement below which is illegal:&lt;BR /&gt;
&lt;BR /&gt;
if conditions ne "" then &lt;BR /&gt;
&lt;BR /&gt;
I expect you will see this error, given the pasted code syntax:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
ERROR: Illegal reference to the array conditions.&lt;BR /&gt;
&lt;BR /&gt;
Suggest you get your code working as a static program, then consider some alternative "more flexible?" methods (possibly more simply using macro logic).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: sbb

Message was edited by: sbb</description>
      <pubDate>Thu, 04 Nov 2010 18:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28595#M5278</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-04T18:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28596#M5279</link>
      <description>Apologies: the forum formatting didn't like square bracket references to array elements. Here it is again:&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
  length outvar condition1 condition2 condition3 condition4 $20;&lt;BR /&gt;
  outvar = "outvar1"; condition1="ge 20"; condition2="eq 1"; condition3="ne 5"; condition4=""; output;&lt;BR /&gt;
  outvar = "outvar2"; condition1=""; condition2=""; condition3="lt 20 "; condition4="eq 1"; output;&lt;BR /&gt;
  outvar = "outvar3"; condition1=""; condition2="eq 1"; condition3="gt 20 "; condition4="eq 1"; output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data _null_in_practice;&lt;BR /&gt;
  length _t $300;&lt;BR /&gt;
  retain _t condition_names1 - condition_names4;&lt;BR /&gt;
  array conditions{*} $20 condition1 - condition4;&lt;BR /&gt;
  array condition_names{1:4} $20 ("condition1" "condition2" "condition3" "condition4");&lt;BR /&gt;
  set test end=last;&lt;BR /&gt;
  if _n_ = 1 then _t="";&lt;BR /&gt;
  do i = 1 to dim(conditions);&lt;BR /&gt;
    if i=1 then _t=trim(left(_t))!!" if ";&lt;BR /&gt;
    if conditions{i} ne "" then&lt;BR /&gt;
     _t = trim(left(_t))!!" ("!!trim(left(condition_names{i}))!!" "&lt;BR /&gt;
     !!trim(left(conditions{i}))!!") and";&lt;BR /&gt;
    if i = dim(conditions) then do;&lt;BR /&gt;
      _t = substr(_t,1,length(_t) - 3)!!" then "!! trim(left(outvar)) !!" = 1; else " &lt;BR /&gt;
      !! trim(left(outvar)) !! " = 0;";&lt;BR /&gt;
    end;&lt;BR /&gt;
  end;&lt;BR /&gt;
  if last then call symput('all_code',trim(left(_t)));&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 04 Nov 2010 18:28:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28596#M5279</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-11-04T18:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28597#M5280</link>
      <description>Suggest bookmarking this page as a favorite for reference - useful reminder for posting special data-strings:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=27609" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=27609&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Also, with arrays, you can use straight left/right parenthesis characters.  Similar to how you can use !!  instead of || (two vertical bars) for concatenation.&lt;BR /&gt;
&lt;BR /&gt;
Are you doing a CALL SYMPUT or a CALL EXECUTE?  How does the code get executed after generating the macro variable?&lt;BR /&gt;
&lt;BR /&gt;
Lastly, I'll ask the question:  What are you looking from the forum to get back with this latest shared information?  BETWEEN doesn't work with IF....that's a given, but it seems as though you are unwilling to code your look-up table such that the IF statement "expression" string (when coded in parentheses as I demonstrated) must have either a single value to compare (EQ, LT, GE, etc.) or a value-range which must then be split into two components the part that goes left of the "varname" and the other component that is to the right.&lt;BR /&gt;
&lt;BR /&gt;
Seems pretty clear to me - the look-up table must be altered to accommodate the IF/THEN logic when you have a value-range to use (which would have been used with a BETWEEN, had this been a WHERE statement/clause).&lt;BR /&gt;
&lt;BR /&gt;
Scott

Message was edited by: sbb</description>
      <pubDate>Thu, 04 Nov 2010 18:33:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28597#M5280</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-04T18:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28598#M5281</link>
      <description>Scott wrote:&lt;BR /&gt;
&amp;gt; Exactly how are you doing the "lookup table"&lt;BR /&gt;
&amp;gt; invocation at SAS compilation time - that would be an&lt;BR /&gt;
&amp;gt; interesting point to clarify?&lt;BR /&gt;
&lt;BR /&gt;
I am not OP, so I can only guess. But it is quite easy to imagine a data step validating a lot of variables based on a lookup table with the variable name as the key that stores validating expression(s) for each variable. Below is an over-simplification (you should *not* rely on the global macro variables as the lookup table.), but illustrates the concept.&lt;BR /&gt;
[pre]&lt;BR /&gt;
   /* validation macro looking up based on var name */&lt;BR /&gt;
   %macro inRange(var);&lt;BR /&gt;
      &amp;amp;&amp;amp;&amp;amp;var.cond&lt;BR /&gt;
   %mend  inRange;&lt;BR /&gt;
&lt;BR /&gt;
   /* prepare lookup table */&lt;BR /&gt;
   data valid;&lt;BR /&gt;
     input var $ cond &amp;amp; $30.;&lt;BR /&gt;
     call symputx(catt(var,"cond"), cond, "g");&lt;BR /&gt;
   cards;&lt;BR /&gt;
   age    13 &amp;lt;= age &amp;lt;= 14&lt;BR /&gt;
   height 63 &amp;lt;= height &amp;lt;=65&lt;BR /&gt;
   ;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
   /* validation */&lt;BR /&gt;
   data _null_;&lt;BR /&gt;
     set sashelp.class;&lt;BR /&gt;
     ageOK = %inRange(age);&lt;BR /&gt;
     heightOK = %inRange(height);&lt;BR /&gt;
     if ageOK and heightOK then put name= age= height=;&lt;BR /&gt;
   run;&lt;BR /&gt;
   /* on log&lt;BR /&gt;
   Name=Henry Age=14 Height=63.5&lt;BR /&gt;
   Name=Judy Age=14 Height=64.3&lt;BR /&gt;
   */&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 04 Nov 2010 18:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28598#M5281</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2010-11-04T18:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28599#M5282</link>
      <description>Thanks guys, the purpose was to see if there was an equivalent of the 'between' operator for the if statement (possibly even enhanced to allow for open, left-open and right-open as well as closed intervals) and this is clearly *not* the case. But I found the catx function and the symputx (as opposed to symput) call routine useful things I didn't know of.</description>
      <pubDate>Thu, 04 Nov 2010 20:54:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28599#M5282</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-11-04T20:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28600#M5283</link>
      <description>Maybe I still don't understand what you're talking about, but then I don't think you do either.&lt;BR /&gt;
&lt;BR /&gt;
To me the statements below confirm that BETWEEN is just a fancy way to write &lt;BR /&gt;
(condition1 and condition2)&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
2200  data class;&lt;BR /&gt;
2201     set sashelp.class;&lt;BR /&gt;
2202     where height between 59 and 65;&lt;BR /&gt;
2203     run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: There were 8 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
&lt;B&gt;      WHERE (height&amp;gt;=59 and height&amp;lt;=65);&lt;/B&gt;&lt;BR /&gt;
NOTE: The data set WORK.CLASS has 8 observations and 5 variables.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
2204  data class;&lt;BR /&gt;
2205     set sashelp.class;&lt;BR /&gt;
2206     where 59 le height le 65;&lt;BR /&gt;
2207     run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: There were 8 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
&lt;B&gt;      WHERE (height&amp;gt;=59 and height&amp;lt;=65);&lt;/B&gt;&lt;BR /&gt;
NOTE: The data set WORK.CLASS has 8 observations and 5 variables.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
2208&lt;BR /&gt;
2209  data class;&lt;BR /&gt;
2210     set sashelp.class;&lt;BR /&gt;
2211     if 59 le height le 65;&lt;BR /&gt;
2212     run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
NOTE: The data set WORK.CLASS has 8 observations and 5 variables.&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 05 Nov 2010 12:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28600#M5283</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-11-05T12:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28601#M5284</link>
      <description>I am physically writing out the code:&lt;BR /&gt;
&lt;BR /&gt;
"IF "!! &lt;READ_VARIABLE_NAME_FROM_TABLE&gt; !! &lt;READ condition="" from="" table=""&gt; !! " then " !!&lt;READ row="" name="" from="" table=""&gt; !! " =1; else " !! &lt;READ row="" name="" from="" table=""&gt; !! " = 0;"&lt;BR /&gt;
&lt;BR /&gt;
For this I need to have a valid value of &lt;READ condition="" from="" table=""&gt; that appears after &lt;READ_VARIABLE_NAME_FROM_TABLE&gt; only and does not need a repetition of &lt;READ_VARIABLE_NAME_FROM_TABLE&gt; to form a valid IF statement. &lt;BR /&gt;
&lt;BR /&gt;
That's the clearest way I can put it.&lt;/READ_VARIABLE_NAME_FROM_TABLE&gt;&lt;/READ_VARIABLE_NAME_FROM_TABLE&gt;&lt;/READ&gt;&lt;/READ&gt;&lt;/READ&gt;&lt;/READ&gt;&lt;/READ_VARIABLE_NAME_FROM_TABLE&gt;</description>
      <pubDate>Fri, 05 Nov 2010 12:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28601#M5284</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-11-05T12:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28602#M5285</link>
      <description>SAS does not support the syntax you are demonstrating -- of course you already know that which is why you are using a DATA step to generate your SAS code.&lt;BR /&gt;
&lt;BR /&gt;
Once again, you are pounding the sand by suggesting that, without BETWEEN support, maybe there might be a suitable resolution for you --- and I provide you an example.  Now you need to revise your DATA step that generates the code, the one with your condition values, and when there is a range-value consideration, you need to have a "low" and a "high" component code piece generated.&lt;BR /&gt;
&lt;BR /&gt;
From your nomenclature, here's what you now need to generate for a range-value:&lt;BR /&gt;
&lt;BR /&gt;
1) identify &lt;READ_VARIABLE_NAME_FROM_TABLE&gt; and determine type of comparison that must be used (LOW, HIGH, EQUAL, RANGE-VALUE, etc.).&lt;BR /&gt;
2) based on #1, construct IF / THEN logic according to the type of comparison.&lt;BR /&gt;
3) construct/append-to SAS variable containing code.&lt;BR /&gt;
4) *repeat above as needed*&lt;BR /&gt;
5) complete DATA step, generate macro variable with SYMPUT - end of DATA step.&lt;BR /&gt;
6) execute macro variable containing generated SAS code.&lt;BR /&gt;
&lt;BR /&gt;
Other techniques to achieve the same result would be to write (using PUT statement) to a "temporary" external sequential file in your main DATA step (no macro variable involved, so there is no implicit code-piece length limit, which no one has discussed here!), and then use %INCLUDE &lt;FILEREF&gt;;   to cause your generated SAS code to get compiled and executed.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/FILEREF&gt;&lt;/READ_VARIABLE_NAME_FROM_TABLE&gt;</description>
      <pubDate>Fri, 05 Nov 2010 12:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28602#M5285</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-05T12:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28603#M5286</link>
      <description>Thanks Scott, excellent thinking there. Actually I didn't know whether or not SAS supported the type of syntax I wanted, which is why I put the post up.&lt;BR /&gt;
&lt;BR /&gt;
Because for any particular &lt;READ-VARIABLE-NAME-FROM-TABLE&gt;,  &lt;READ condition="" from="" table=""&gt; can contain (on different rows) both conditions that don't need code modification and conditions that do need code modification, what I actually did since yesterday is:&lt;BR /&gt;
&lt;BR /&gt;
1) text-search &lt;READ condition="" from="" table=""&gt; for " and ", " &amp;amp; ", " or ", " | " (with an implicit rule that there must be a space inserted in the condition cell as shown if any of these strings appears).&lt;BR /&gt;
2) if 1) is false, proceed as given in previous post.&lt;BR /&gt;
3) if 1) is true, break down the &lt;READ-CONDITION-FROM-TABLE&gt; into three sub-strings: a) part before " and " or " or ", b) " and " or " or " c) part after " and " or "or ". Then modify the code to: "IF " &lt;READ-VARIABLE-NAME-FROM-TABLE&gt; &lt;SUBSTRING a=""&gt; &lt;SUBSTRING b=""&gt; &lt;READ-VARIABLE-NAME-FROM-TABLE&gt; &lt;SUBSTRING c=""&gt; " then " &lt;READ-ROW-NAME-FROM-TABLE&gt; " =1; else " &lt;READ-ROW-NAME-FROM-TABLE&gt; " =0;"&lt;BR /&gt;
&lt;BR /&gt;
An example of a &lt;READ-CONDITION-FROM-TABLE&gt; that doesn't need modification is "ge 5.2". An example of one that does need above modification is "ge 5.2 and le 9.1".&lt;BR /&gt;
&lt;BR /&gt;
Cheers,&lt;BR /&gt;
Steve&lt;/READ-CONDITION-FROM-TABLE&gt;&lt;/READ-ROW-NAME-FROM-TABLE&gt;&lt;/READ-ROW-NAME-FROM-TABLE&gt;&lt;/SUBSTRING&gt;&lt;/READ-VARIABLE-NAME-FROM-TABLE&gt;&lt;/SUBSTRING&gt;&lt;/SUBSTRING&gt;&lt;/READ-VARIABLE-NAME-FROM-TABLE&gt;&lt;/READ-CONDITION-FROM-TABLE&gt;&lt;/READ&gt;&lt;/READ&gt;&lt;/READ-VARIABLE-NAME-FROM-TABLE&gt;</description>
      <pubDate>Fri, 05 Nov 2010 13:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28603#M5286</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-11-05T13:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: Open and closed intervals in the if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28604#M5287</link>
      <description>Exactly - then you now understand that the look-up table must have a suitable alternative construct to address the fact that "BETWEEN" is not supported in a SAS DATA step's IF/THEN construct, correct?&lt;BR /&gt;
&lt;BR /&gt;
And, the next step would be for you to go off and make such changes - to mean that your post to this forum is complete/satisfied, correct?&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 05 Nov 2010 13:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-and-closed-intervals-in-the-if-statement/m-p/28604#M5287</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-05T13:28:53Z</dc:date>
    </item>
  </channel>
</rss>

