A LINE statement value can be conditionally printed by using a text string and adjusting the format length.
A LINE statement from a COMPUTE BEFORE and a COMPUTE AFTER block will execute every time the COMPUTE block is processed. When a LINE statement is within an IF statement, the LINE statement will still be executed even when the IF condition is FALSE.
A text string can be changed based on the condition code. When the LINE statement is executed, only the values of the text string will be printed. In the code below, the text string contains a value when the IF statement is TRUE, and another value when the IF statement is FALSE. A LENGTH statement is added to avoid truncation of the text string.
The output from the code above shows a text string when the IF condition is TRUE and a blank line when the IF condition is FALSE. Even though there is an IF statement prior to the LINE statement, the LINE statement executes every time the COMPUTE block is processed.
If the desired output is to only print a line of output when there are values, then the code above will not work. The only way to produce a null LINE statement is to use a zero format length for the text string. The $VARYING format is used because of the flexibility of changing the length of the format.
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 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.
Output from the first sample code
Conditional output printed from the LINE statement Name Gender Age Height Weight Joyce F 11 51.3 50.5 Thomas M 57.5 85 James M 12 57.3 83 Jane F 59.8 84.5 John M 59 99.5 Louise F 56.3 77 Robert M 64.8 128 Alice F 13 56.5 84 Barbara F 65.3 98 Jeffrey M 62.5 84 Alfred M 14 69 112.5 Carol F 62.8 102.5 Henry M 63.5 102.5 Judy F 64.3 90 Janet F 15 62.5 112.5 Mary F 66.5 112 Ronald M 67 133 William M 66.5 112 for age=15 only Philip M 16 72 150Output from the second sample code
Conditional output printed from the LINE statement Conditional LINE statement processing for null lines of output Name Gender Age Height Weight Joyce F 11 51.3 50.5 Thomas M 57.5 85 James M 12 57.3 83 Jane F 59.8 84.5 John M 59 99.5 Louise F 56.3 77 Robert M 64.8 128 Alice F 13 56.5 84 Barbara F 65.3 98 Jeffrey M 62.5 84 Alfred M 14 69 112.5 Carol F 62.8 102.5 Henry M 63.5 102.5 Judy F 64.3 90 Janet F 15 62.5 112.5 Mary F 66.5 112 Ronald M 67 133 William M 66.5 112 for age=15 only Philip M 16 72 150
Type: | Sample |
Date Modified: | 2020-02-12 13:54:20 |
Date Created: | 2009-11-09 12:49:55 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | z/OS | ||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 7 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows XP Professional | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |