MINDELIMITER Macro In Delimiter

From sasCommunity
Jump to: navigation, search

Q: How do I use the %in logical operator in the macro language?

Opinion

From A Little Birdie, developer/maintainer of the SAS Macro Language:

There is no "%in". There probably will be no "%in", as that name could possibly already be used by a user to define a macro.

What does exist is "in" or "#". You may remember that "in" was not initially well received, so it was disabled in V9.13.

In V9.2, the option MINOPERATOR was added so that users could enable "in". This is all in the V9.2 online documentation.

Attached [below] is a log showing the use of "in", "#", and the MINOPERATOR option. Note that MINOPERATOR can be specified on macro definitions so that the author of the macro controls whether the operator is available. (You should also note that the MINDELIMITER option can likewise be specified on macro definitions for the same reason.)

Tech Support Note

http://support.sas.com/kb/35/591.html

Be sure to see the code sample available on the "Full Code" tab.

The Log

1 The SAS System                            13:08 Friday, November 21, 2008

NOTE: Copyright (c) 2002-2008 by SAS Institute Inc., Cary, NC, USA. 
NOTE: SAS (r) Proprietary Software 9.2 (TS2M0) 
      Licensed to SAS Institute Inc., Site 1.
NOTE: This session is executing on the XP_PRO  platform.

NOTE: SAS initialization used:
      real time           0.29 seconds
      cpu time            0.31 seconds
      
1          /**************************************/
2          /* First test Open Code statements    */
3          /**************************************/
4          
5          %put %eval(a IN abc def a ghi); /* ERROR - NOMINOPERATOR is the default */

ERROR: A character operand was found in the %EVAL function or %IF condition 
where a numeric operand is required. The condition was: 
       a IN abc def a ghi 
 
6          %put %eval(a # abc def a ghi);  /* ERROR - NOMINOPERATOR is the default */

ERROR: A character operand was found in the %EVAL function or %IF condition 
where a numeric operand is required. The condition was: 
       a # abc def a ghi 
 
7          
8          options MINOPERATOR;
9          
10         %put ** %eval(a IN abc def ghi) **;   /* Should print ** 0 ** */
** 0 **
11         %put ** %eval(a IN abc def a ghi) **; /* Should print ** 1 ** */
** 1 **
12         %put ** %eval(a # abc def a ghi) **;  /* Should print ** 1 ** */
** 1 **
13         
14         /**************************************/
15         /* Next test Session Compiled macros  */
16         /**************************************/
17         
18         options NOMINOPERATOR;
19         
20         %macro mindef;
21            %if a IN abc def ghi %then
22               %put ERROR!;
23            %else
24               %put CORRECT! a is not "in" abc def ghi.;
25            %if a # abc def ghi %then
26               %put ERROR!;
27            %else
28               %put CORRECT! a is not "#" abc def ghi.;
29            %if a IN abc def a ghi %then
30               %put CORRECT! a is "in" abc def a ghi.;
31            %else
32               %put ERROR!;
33         
34            %if a # abc def a ghi %then
35               %put CORRECT! a is # abc def a ghi.;
36            %else
37               %put ERROR!;
38         %mend mindef;
39         %macro minon/ MINOPERATOR;
40            %if a IN abc def ghi %then
41               %put ERROR!;
42            %else
43               %put CORRECT! a is not "in" abc def ghi.;
44            %if a # abc def ghi %then
45               %put ERROR!;
46            %else
47               %put CORRECT! a is not "#" abc def ghi.;
48            %if a IN abc def a ghi %then
49               %put CORRECT! a is "in" abc def a ghi.;
50            %else
51               %put ERROR!;
52         
53            %if a # abc def a ghi %then
54               %put CORRECT! a is # abc def a ghi.;
55            %else
56               %put ERROR!;
57         %mend minon;
58         %macro minoff/ NOMINOPERATOR;
59            %if a IN abc def ghi %then
60               %put ERROR!;
61            %else
62               %put CORRECT! a is not "in" abc def ghi.;
63            %if a # abc def ghi %then
64               %put ERROR!;
65            %else
66               %put CORRECT! a is not "#" abc def ghi.;
67            %if a IN abc def a ghi %then
68               %put CORRECT! a is "in" abc def a ghi.;
69            %else
70               %put ERROR!;
71         
72            %if a # abc def a ghi %then
73               %put CORRECT! a is # abc def a ghi.;
74            %else
75               %put ERROR!;
76         %mend minoff;
77         
78         /* NOMINOPERATOR is the default value of the global option */
79         
80         %mindef; /* Should cause ERROR when option is NOMINDELIMETER */

ERROR: A character operand was found in the %EVAL function or %IF condition 
where a numeric operand is required. The condition was: 
       a IN abc def ghi 
ERROR: The macro MINDEF will stop executing.
81         %minon;  /* Should never ERROR regardless of global option   */
CORRECT! a is not "in" abc def ghi.
CORRECT! a is not "#" abc def ghi.
CORRECT! a is "in" abc def a ghi.
CORRECT! a is # abc def a ghi.
82         %minoff; /* Should always ERROR regardless of global option  */

ERROR: A character operand was found in the %EVAL function or %IF condition 
where a numeric operand is required. The condition was: 
       a IN abc def ghi 
ERROR: The macro MINOFF will stop executing.
83         
84         options MINOPERATOR;
85         
86         %mindef; /* Should cause ERROR when option is NOMINDELIMETER */
CORRECT! a is not "in" abc def ghi.
CORRECT! a is not "#" abc def ghi.
CORRECT! a is "in" abc def a ghi.
CORRECT! a is # abc def a ghi.
87         %minon;  /* Should never ERROR regardless of global option   */
CORRECT! a is not "in" abc def ghi.
CORRECT! a is not "#" abc def ghi.
CORRECT! a is "in" abc def a ghi.
CORRECT! a is # abc def a ghi.
88         %minoff; /* Should always ERROR regardless of global option  */
ERROR: A character operand was found in the %EVAL function or %IF condition 
where a numeric operand is required. The condition was: 
       a IN abc def ghi 
ERROR: The macro MINOFF will stop executing.
89         
90         /****************************/
91         /* Now test Autocall Macros */
92         /****************************/
93         
94         option sasautos=("./automlib");
95         
96         option NOMINOPERATOR;
97         
98         %automindef; /* Should cause ERROR when option is NOMINDELIMETER */
ERROR: A character operand was found in the %EVAL function or %IF condition 
where a numeric operand is required. The condition was: 
       a IN abc def ghi 
ERROR: The macro AUTOMINDEF will stop executing.
99         %autominon;  /* Should never ERROR regardless of global option   */
CORRECT! a is not "in" abc def ghi.
CORRECT! a is not "#" abc def ghi.
CORRECT! a is "in" abc def a ghi.
CORRECT! a is # abc def a ghi.
100        %autominoff; /* Should always ERROR regardless of global option  */
ERROR: A character operand was found in the %EVAL function or %IF condition 
where a numeric operand is required. The condition was: 
       a IN abc def ghi 
ERROR: The macro AUTOMINOFF will stop executing.
101        
102        options MINOPERATOR;
103        
104        %automindef; /* Should cause ERROR when option is NOMINDELIMETER */
CORRECT! a is not "in" abc def ghi.
CORRECT! a is not "#" abc def ghi.
CORRECT! a is "in" abc def a ghi.
CORRECT! a is # abc def a ghi.
105        %autominon;  /* Should never ERROR regardless of global option   */
CORRECT! a is not "in" abc def ghi.
CORRECT! a is not "#" abc def ghi.
CORRECT! a is "in" abc def a ghi.
CORRECT! a is # abc def a ghi.
106        %autominoff; /* Should always ERROR regardless of global option  */
ERROR: A character operand was found in the %EVAL function or %IF condition 
where a numeric operand is required. The condition was: 
       a IN abc def ghi 
ERROR: The macro AUTOMINOFF will stop executing.
107        
108        /****************************************/
109        /* Finally, test Stored-Compiled macros */
110        /****************************************/
111        
112        libname scmlib "./scmlib";
NOTE: Libref SCMLIB was successfully assigned as follows: 
      Engine:        V9 
      Physical Name: \\ge\U101\sasedv\work\s0321957\scmlib
113        option mstored sasmstore=scmlib;
114        %macro scmindef/ store;
115           %if a IN abc def ghi %then
116              %put ERROR!;
117           %else
118              %put CORRECT! a is not "in" abc def ghi.;
119           %if a # abc def ghi %then
120              %put ERROR!;
121           %else
122              %put CORRECT! a is not "#" abc def ghi.;
123           %if a IN abc def a ghi %then
124              %put CORRECT! a is "in" abc def a ghi.;
125           %else
126              %put ERROR!;
127        
128           %if a # abc def a ghi %then
129              %put CORRECT! a is # abc def a ghi.;
130           %else
131              %put ERROR!;
132        %mend scmindef;
133        %macro scminon/  store MINOPERATOR;
134           %if a IN abc def ghi %then
135              %put ERROR!;
136           %else
137              %put CORRECT! a is not "in" abc def ghi.;
138           %if a # abc def ghi %then
139              %put ERROR!;
140           %else
141              %put CORRECT! a is not "#" abc def ghi.;
142           %if a IN abc def a ghi %then
143              %put CORRECT! a is "in" abc def a ghi.;
144           %else
145              %put ERROR!;
146        
147           %if a # abc def a ghi %then
148              %put CORRECT! a is # abc def a ghi.;
149           %else
150              %put ERROR!;
151        %mend scminon;
152        %macro scminoff/ store NOMINOPERATOR;
153           %if a IN abc def ghi %then
154              %put ERROR!;
155           %else
156              %put CORRECT! a is not "in" abc def ghi.;
157           %if a # abc def ghi %then
158              %put ERROR!;
159           %else
160              %put CORRECT! a is not "#" abc def ghi.;
161           %if a IN abc def a ghi %then
162              %put CORRECT! a is "in" abc def a ghi.;
163           %else
164              %put ERROR!;
165        
166           %if a # abc def a ghi %then
167              %put CORRECT! a is # abc def a ghi.;
168           %else
169              %put ERROR!;
170        %mend scminoff;
171        
172        option NOMINOPERATOR;
173        
174        %scmindef; /* Should cause ERROR when option is NOMINDELIMETER */
ERROR: A character operand was found in the %EVAL function or %IF condition 
where a numeric operand is required. The condition was: 
       a IN abc def ghi 
ERROR: The macro SCMINDEF will stop executing.
175        %scminon;  /* Should never ERROR regardless of global option   */
CORRECT! a is not "in" abc def ghi.
CORRECT! a is not "#" abc def ghi.
CORRECT! a is "in" abc def a ghi.
CORRECT! a is # abc def a ghi.
176        %scminoff; /* Should always ERROR regardless of global option  */
ERROR: A character operand was found in the %EVAL function or %IF condition 
where a numeric operand is required. The condition was: 
       a IN abc def ghi 
ERROR: The macro SCMINOFF will stop executing.
177        
178        options MINOPERATOR;
179        
180        %scmindef; /* Should cause ERROR when option is NOMINDELIMETER */
CORRECT! a is not "in" abc def ghi.
CORRECT! a is not "#" abc def ghi.
CORRECT! a is "in" abc def a ghi.
CORRECT! a is # abc def a ghi.
181        %scminon;  /* Should never ERROR regardless of global option   */
CORRECT! a is not "in" abc def ghi.
CORRECT! a is not "#" abc def ghi.
CORRECT! a is "in" abc def a ghi.
CORRECT! a is # abc def a ghi.
182        %scminoff; /* Should always ERROR regardless of global option  */
ERROR: A character operand was found in the %EVAL function or %IF condition 
where a numeric operand is required. The condition was: 
       a IN abc def ghi 
ERROR: The macro SCMINOFF will stop executing.

ERROR: Errors printed on page 1.

NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
NOTE: The SAS System used:
      real time           0.39 seconds
      cpu time            0.35 seconds

From the OnLine Doc

  • Macro Language Dictionary
    • MINDELIMITER= System Option
%put %eval(a in d,e,f,a,b,c); /* should print 0 */

%put %eval(a in d e f a b c); /* should print 1 */

option mindelimiter=',';
%put %eval(a in d,e,f,a,b,c); /* should print 1 */

%put %eval(a in d e f a b c); /* should print 0 */


--macro maven == the radical programmer 16:34, 3 December 2008 (EST)