Usage Note 37328: All expressions are evaluated in compound expressions
When statements such as DO WHILE, DO UNTIL, and IF, as well as functions such IFC and IFN, contain compound expressions to be evaluated, all expressions are evaluated prior to determining the overall truth of the compound expression. This can lead to unexpected warning or error messages in the SAS log when you anticipate that expressions are evaluated in the order in which they appear.
The evaluations do not cease when the overall truth could be determined without evaluating all expressions.
To prevent these unexpected messages, do not write code that depends on the order of evaluation or relies on fewer than every expression being evaluated.
Operating System and Release Information
| SAS System | Base SAS | Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS2M0 | |
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS2M0 | |
| Microsoft Windows XP 64-bit Edition | 9.2 TS2M0 | |
| Microsoft® Windows® for x64 | 9.2 TS2M0 | |
| Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS2M0 | |
| Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS2M0 | |
| Microsoft Windows Server 2003 Standard Edition | 9.2 TS2M0 | |
| Microsoft Windows XP Professional | 9.2 TS2M0 | |
| Windows Vista | 9.2 TS2M0 | |
| 64-bit Enabled AIX | 9.2 TS2M0 | |
| 64-bit Enabled HP-UX | 9.2 TS2M0 | |
| 64-bit Enabled Solaris | 9.2 TS2M0 | |
| z/OS | 9.2 TS2M0 | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS2M0 | |
| HP-UX IPF | 9.2 TS2M0 | |
| Linux | 9.2 TS2M0 | |
| Linux for x64 | 9.2 TS2M0 | |
| OpenVMS on HP Integrity | 9.2 TS2M0 | |
| Solaris for x64 | 9.2 TS2M0 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
/* create test data */
data test;
infile datalines truncover;
input ID :$3. chgdate ??mmddyy10.;
format chgdate date9.;
datalines;
aaa .
bbb 1/1/2009
ccc 1/1/2008
ddd 1/1/2007
eee 1/1/2006
fff .
ggg 9/1/2009
hhh 8/1/2009
iii 7/1/2009
jjj 6/1/2009
kkk 5/1/2009
mmm .
nnn 4/1/2009
ppp 3/1/2009
qqq 2/1/2009
;
/* generates warning message */
%let dt = '02Oct2009'd;
data result1 ;
set test;
IF not (CHGDATE = . OR &dt - CHGDATE > 370) THEN
output;
run;
/* does not generate warning message */
data result2 ;
set test;
if chgdate ne .;
IF not( &dt - CHGDATE > 370) THEN
output;
run;
Output when messages are generated
Obs ID chgdate
1 bbb 01JAN2009
2 ggg 01SEP2009
3 hhh 01AUG2009
4 iii 01JUL2009
5 jjj 01JUN2009
6 kkk 01MAY2009
7 nnn 01APR2009
8 ppp 01MAR2009
9 qqq 01FEB2009
Output when no messages are generated
Obs ID chgdate
1 bbb 01JAN2009
2 ggg 01SEP2009
3 hhh 01AUG2009
4 iii 01JUL2009
5 jjj 01JUN2009
6 kkk 01MAY2009
7 nnn 01APR2009
8 ppp 01MAR2009
9 qqq 01FEB2009
All expressions in a compound expression are evaluated regardless of whether the Boolean truth of the compound expression could be determined by evaluating only the first or less than every expression.
| Type: | Usage Note |
| Priority: | |
| Topic: | Common Programming Tasks ==> Selecting Data Common Programming Tasks ==> Reading and Writing SAS Data Common Programming Tasks ==> Combining Data Common Programming Tasks ==> Conditional Processing SAS Reference ==> Statements ==> Action ==> IF, subsetting SAS Reference ==> DATA Step SAS Reference ==> Statements ==> Control ==> DO UNTIL SAS Reference ==> Statements ==> Control ==> DO WHILE SAS Reference ==> Statements ==> Control ==> IF-THEN/ELSE SAS Reference ==> Functions ==> Character ==> IFC SAS Reference ==> Functions ==> Character ==> IFN
|
| Date Modified: | 2011-01-17 13:34:21 |
| Date Created: | 2009-10-02 12:45:13 |