Sample 40271: Conditional execution using only a function
This sample illustrates how to use the IFC function which uses conditional logic that enables you to select among several different values based on the value of a logical expression. With the use of this function you could avoid having to place your code within a macro and do the same task in one line of code.
This sample gives you both ways. How to conditionally create a macro variable using a %IF statement, or use the IFC function outside a macro and create the same macro variable in one statement.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/** These 2 examples do the same thing but the first one does not require a **/
/** macro definition. **/
/** Example 1. **/
/** No %IF needed **/
%let val=0;
%let var=%sysfunc(ifc(&val=1,one,zero));
%put &var;
/** Example 2. **/
/** %IF needed **/
%macro test(val);
%if &val=1 %then %let var=one;
%else %let var=zero;
%put &var;
%mend;
%test(0)
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/** Results from log **/
1 /** Example 1. **/
2 /** No %IF needed **/
3
4 %let val=0;
5 %let var=%sysfunc(ifc(&val=1,one,zero));
6 %put &var;
zero
7
8 /** Example 2. **/
9 /** %IF needed **/
10
11 %macro test(val);
12 %if &val=1 %then %let var=one;
13 %else %let var=zero;
14 %put &var;
15 %mend;
16
17 %test(0)
zero
This sample shows how to conditionally execute statements without having to use a macro %IF statement.
Date Modified: | 2012-04-02 13:21:19 |
Date Created: | 2010-07-08 12:33:32 |
Operating System and Release Information
SAS System | Base SAS | z/OS | 9.1 TS1M3 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M3 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.1 TS1M3 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.1 TS1M3 | |
Microsoft Windows XP 64-bit Edition | 9.1 TS1M3 | |
Microsoft Windows 2000 Advanced Server | 9.1 TS1M3 | |
Microsoft Windows 2000 Datacenter Server | 9.1 TS1M3 | |
Microsoft Windows 2000 Server | 9.1 TS1M3 | |
Microsoft Windows 2000 Professional | 9.1 TS1M3 | |
Microsoft Windows NT Workstation | 9.1 TS1M3 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.1 TS1M3 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.1 TS1M3 | |
Microsoft Windows Server 2003 Standard Edition | 9.1 TS1M3 | |
Microsoft Windows XP Professional | 9.1 TS1M3 | |
Windows Vista | 9.1 TS1M3 | |
Windows Vista for x64 | 9.1 TS1M3 | |
64-bit Enabled AIX | 9.1 TS1M3 | |
64-bit Enabled HP-UX | 9.1 TS1M3 | |
64-bit Enabled Solaris | 9.1 TS1M3 | |
HP-UX IPF | 9.1 TS1M3 | |
Linux | 9.1 TS1M3 | |
OpenVMS Alpha | 9.1 TS1M3 | |
Tru64 UNIX | 9.1 TS1M3 | |