```Date: Wed, 15 Feb 2012 17:04:45 -0500 Reply-To: Talbot Michael Katz Sender: "SAS(r) Discussion" From: Talbot Michael Katz Subject: Double inequality and macros Hi! This is an issue I may have asked about in the past. The Base SAS language allows a "double inequality" construction, as follows: **********************************************************************; 135 data _null_ ; 136 * parm = . ; 137 parm = 7 ; 138 if 1 < parm le 100 then do ; 139 put parm = " between 1 and 100" ; 140 end ; 141 else do ; 142 put "Where am I?" ; 143 end ; 144 run ; parm=7 between 1 and 100 NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds 145 146 data _null_ ; 147 * parm = . ; 148 * parm = 7 ; 149 parm = 0 ; 150 if 1 < parm le 100 then do ; 151 put parm = " between 1 and 100" ; 152 end ; 153 else do ; 154 put "Where am I?" ; 155 end ; 156 run ; Where am I? NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds **********************************************************************; Suppose I try to do a similar thing inside a macro 49 %macro tdi(parm) ; 50 51 %if 1 < &parm. le 100 %then %do ; 52 %put parm = &parm. between 1 and 100 ; 53 %end ; 54 %else %do ; 55 %put Where am I? ; 56 %end ; 57 58 %mend tdi ; 59 60 %tdi() ; parm = between 1 and 100 61 62 %tdi(222) ; parm = 222 between 1 and 100 63 64 %tdi(0) ; parm = 0 between 1 and 100 **********************************************************************; The macro version does not work the way I intended. I can get it to work with separate single inequalities joined by "AND": 70 %macro tdi2(parm) ; 71 72 %if (1 < &parm.) and (&parm. le 100) %then %do ; 73 %put parm = &parm. between 1 and 100 ; 74 %end ; 75 %else %do ; 76 %put Where am I? ; 77 %end ; 78 79 %mend tdi2 ; 80 81 82 %tdi2() ; Where am I? 83 84 85 %tdi2(222) ; Where am I? 86 87 88 %tdi2(0) ; Where am I? 89 90 %tdi2(boosky) ; Where am I? 91 92 %tdi2(10) ; parm = 10 between 1 and 100 **********************************************************************; Am I doing something wrong? Is it the case the the double inequality simply doesn't work in macros, or is there perhaps a clever way to salvage it? I am using SAS 9.2 on Windows. Thanks! -- TMK -- (The Macro Klutz) ```

Back to: Top of message | Previous page | Main SAS-L page