Usage Note 37411: SCAN function enhancements in SAS® 9.2
The new modifier argument on the SCAN function enables leading, trailing, and multiple embedded delimiters to be treated like the DSD option on an INFILE statement. The modifiers are treated as delimiters between null values.
The following example, which is taken from the SAS® 9.2 Language Reference: Dictionary, Second Edition, shows the results of using the M modifier with a comma as a delimiter. With the M modifier, leading, trailing, and multiple consecutive delimiters cause the SCAN function to return words that have a length of zero. Therefore, you should not end the loop by testing for a blank word. Instead, you can use the COUNTW function with the same modifiers and delimiters to count the words in the string.
The O modifier is used for efficiency because the delimiters and modifiers are the same in every call to the SCAN and COUNTW functions.
options pageno=1 nodate ls=80 ps=64;
data comma;
keep count word;
length word $30;
string = ',leading, trailing,and multiple,,delimiters,,';
delim = ',';
modif = 'mo'; *m accept multiple delimiters, o processes the charlist
and modifier arguments only once, rather than every time
the SCAN function is called;
nwords = countw(string, delim, modif);
do count = 1 to nwords;
word = scan(string, count, delim, modif);
output;
end;
run;
proc print data=comma noobs;
run;
Results of Finding All Words by Using the M and O Modifiers
The SAS System 1
word count
1
leading 2
trailing 3
and multiple 4
5
delimiters 6
7
8
Operating System and Release Information
| SAS System | N/A | Microsoft® Windows® for x64 | 9.2 TS1M0 | |
| Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |
| z/OS | 9.2 TS1M0 | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 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 | |
*
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.
| Date Modified: | 2009-10-19 12:16:39 |
| Date Created: | 2009-10-09 11:15:17 |