Sample 24716: Replace unprintable characters from character variables with blanks
The sample code on the Full Code tab illustrates how to use character variable functions to remove nonprintable characters from character variables.
Note: This sample illustrates the NOTPRINT function, available in SAS® 9.0 and above, as well as the VERIFY function.
The VERIFY function is used to locate any byte that is not in the acceptable list of characters. Using the UPCASE function shortens the list by 26 alpha characters. Be sure to include valid punctuation, white space, and digits.
To test the VERIFY function, comment out the NOTPRINT logic and uncomment the VERIFY logic.
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.
/* Create sample data */
/* The hex values 05, 0D, 0C, and 0A are all nonprintable printable characters on an ASCII operating system */
data sample;
string='Your'||'05'x||'data'||'0D'x||'goes'||'0C'x||'here.'||'0A'x;
run;
data _null_;
set sample;
put 'Original string=' +1 string;
/* Verify each byte in the string until no more nonprintables are found */
do until(test=0);
/* For SAS 9.0 and above, NOTPRINT */
test=notprint(string);
/* If a nonprintable is found...replace it with a space */
if test>0 then do;
substr(string,test,1)=' ';
end;
end;
put 'Updated string=' +1 string;
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.
OUTPUT to SAS log
string=Your[]data
goes[]here.
string=Your data goes here.
Use character variable functions to replace nonprintable characters from character variables with blanks.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions ==> Character
|
Date Modified: | 2007-11-07 14:40:09 |
Date Created: | 2004-09-30 14:09:07 |
Operating System and Release Information
SAS System | Base SAS | z/OS | 9 TS M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9 TS M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9 TS M0 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9 TS M0 | |
Microsoft Windows 2000 Advanced Server | 9 TS M0 | |
Microsoft Windows 2000 Datacenter Server | 9 TS M0 | |
Microsoft Windows 2000 Server | 9 TS M0 | |
Microsoft Windows 2000 Professional | 9 TS M0 | |
Microsoft Windows NT Workstation | 9 TS M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9 TS M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9 TS M0 | |
Microsoft Windows Server 2003 Standard Edition | 9 TS M0 | |
Microsoft Windows XP Professional | 9 TS M0 | |
64-bit Enabled AIX | 9 TS M0 | |
64-bit Enabled HP-UX | 9 TS M0 | |
64-bit Enabled Solaris | 9 TS M0 | |
HP-UX IPF | 9 TS M0 | |
Linux | 9 TS M0 | |
OpenVMS Alpha | 9 TS M0 | |
Tru64 UNIX | 9 TS M0 | |