The DLMSTR= option for the INFILE statement is available beginning in SAS 9.2. DLMSTR stands for "delimiter string'. This option enables programmers to specify a multi-character string as a delimiter. For example, DLMSTR="-/-" treats these three characters, in this order, as a delimiter. Prior to this option, each individual character specified in the DLM= option would have been treated singularly as a delimiter.
The DLMSTR= option supports specifying a character variable after the equal sign. The value in the variable is used as the delimiter.
DLMSTR= is also supported on the FILE statement, enabling users to write data with multi-character string delimiters.
If there are consecutive delimiter strings in the file which indicate missing values, the DLMSTR= option will not read the file properly until SAS 9.3. This SAS note 38147 gives more information about this issue.
If there are consecutive delimiter strings in the file that is being read in and the release of SAS is prior to 9.3, the PRXCHANGE function with _INFILE_ can be used to change the multiple delimiters to one delimiter and then reread _INFILE_. See the third program under the Full Code tab.
Product Family | Product | System | SAS Release | |
Reported | Fixed* | |||
SAS System | Base SAS | z/OS | 9.2 TS1M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |||
Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |||
Microsoft® Windows® for x64 | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |||
Microsoft Windows XP Professional | 9.2 TS1M0 | |||
Windows Vista | 9.2 TS1M0 | |||
64-bit Enabled AIX | 9.2 TS1M0 | |||
64-bit Enabled HP-UX | 9.2 TS1M0 | |||
64-bit Enabled Solaris | 9.2 TS1M0 | |||
HP-UX IPF | 9.2 TS1M0 | |||
Linux | 9.2 TS1M0 | |||
Linux for x64 | 9.2 TS1M0 | |||
OpenVMS on HP Integrity | 9.2 TS1M0 | |||
Solaris for x64 | 9.2 TS1M0 |
/* Specify multiple delimiters with the DLMSTR= option along with */
/* the DSD option so that the string @# is considered one delimiter */
data a;
infile datalines dlmstr='@#' dsd truncover;
input x y z;
datalines;
123@#-456@#789
;
proc print;
run;
/* Put this data set out to a file and use DLMSTR= option on */
/* the FILE statement to specify the delimiter string. */
data _null_;
set a;
file 'c:\myfile.txt' dlmstr='@#';
put x y z;
run;
/* If your file contains consecutive delimiter strings and you're */
/* running SAS prior to 9.3, you will need the following program. */
/* Create a file with consecutive delimiter strings so you can */
/* test the program that follows. Specify the path of your */
/* choice inside quotes on the FILE statement. */
data _null_;
file 'your-file-specification';
put'123@#456@#@#789';
run;
/* If there are consecutive delimiter strings in the file you're*/
/* reading, you can use PRXCHANGE to temporarily change them to */
/* a single delimiter so the file is read correctly. */
/* The null INPUT statement reads a record into the input buffer*/
/* which is accessible as the automatic variable, _INFILE_. Use */
/* the PRXCHANGE function to temporarily change the @# delimiter*/
/* string to a ~. That character was declared as the delimiter */
/* with the DLM= option on the INFILE statement so the INPUT */
/* statement can now read the file properly. */
data a;
infile 'your-file-specification' truncover dlm='~' dsd;
input @;
_infile_=prxchange("s/@#/~/",-1,_infile_);
input @1 a b c d ;
proc print;
run;
Obs x y z 1 123 -456 789 /* results in the file created with second DATA step */ 123@#-456@#789 /* results of using PRXCHANGE to read the consecutive delimiter strings */ Obs a b c d 1 123 456 . 789
Type: | Usage Note |
Priority: | |
Topic: | SAS Reference ==> Statements ==> File-handling ==> INFILE SAS Reference ==> Statements ==> File-handling ==> FILE |
Date Modified: | 2011-01-18 15:40:38 |
Date Created: | 2008-09-23 12:49:11 |