Sample 45289: Conditional Logic with the INPUT Statement and Trailing @
The sample within the Full Code tab shows how to use a single trailing @ in the INPUT statement to hold a portion of the input record within the input buffer. Conditional logic can then be used to determine how to read the remaining portion of each record.
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.
The comma delimited data is read up through the third variable and the trailing @ holds the input record. The ANYDIGIT function is used to view the contents of the COUNT variable and if any numeric digit (0-9) is found the function returns the position found. If the result is greater than 0 (zero) a number is found. Next, a DO loop is used to iterate the number of times equal to the COUNT value to read in the remaining number of parts on the record. The OUTPUT statement is used within the DO loop to create a new observation for each part.
If the ANYDIGIT function returns a 0 (zero) a number was not found. The PART variable is set to the COUNT value and the single observation is output.
data parts;
infile datalines dsd truncover;
input dept color : $10. count $ @;
if anydigit(count) > 0 then do;
do i = 1 to input(count,2.);
input part $ @;
output;
end;
end;
else do;
part=count;
output;
end;
drop i count;
datalines;
101,Green,3,A,B,C
102,Blue,A
103,Purple,F
104,Red,4,A,C,D,F
105,Orange,2,A,B
106,Yellow,E
;
run;
proc print;
run;
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.
The SAS System
Obs dept color part
1 101 Green A
2 101 Green B
3 101 Green C
4 102 Blue A
5 103 Purple F
6 104 Red A
7 104 Red C
8 104 Red D
9 104 Red F
10 105 Orange A
11 105 Orange B
12 106 Yellow E
Using the trailing @ in the INPUT statement to hold a portion of an input record within the input buffer, allowing for conditional logic to determine how to read the rest of the record.
Type: | Sample |
Topic: | SAS Reference ==> Statements ==> File-handling ==> INFILE SAS Reference ==> Statements ==> File-handling ==> INPUT
|
Date Modified: | 2019-06-11 14:57:13 |
Date Created: | 2012-01-05 10:41:37 |
Operating System and Release Information
SAS System | Base SAS | Aster Data nCluster on Linux x64 | | |
DB2 Universal Database on AIX | | |
DB2 Universal Database on Linux x64 | | |
Greenplum on Linux x64 | | |
Netezza TwinFin 32bit blade | | |
Netezza TwinFin 32-bit SMP Hosts | | |
Netezza TwinFin 64-bit S-Blades | | |
Netezza TwinFin 64-bit SMP Hosts | | |
Teradata on Linux | | |
z/OS | | |
Z64 | | |
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 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 2003 for x64 | | |
Microsoft Windows Server 2008 | | |
Microsoft Windows Server 2008 for x64 | | |
Microsoft Windows XP Professional | | |
Windows 7 Enterprise 32 bit | | |
Windows 7 Enterprise x64 | | |
Windows 7 Home Premium 32 bit | | |
Windows 7 Home Premium x64 | | |
Windows 7 Professional 32 bit | | |
Windows 7 Professional x64 | | |
Windows 7 Ultimate 32 bit | | |
Windows 7 Ultimate x64 | | |
Windows Millennium Edition (Me) | | |
Windows Vista | | |
Windows Vista for x64 | | |
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 | | |