Sample 24716: Deleting unprintable characters from character variables
Use character variable functions to remove non-printable
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 not in the
acceptable list of characters. Using the UPCASE function
shortens the list by 26 alpha-characters. Be sure to
include valid punctuation and 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 */
data sample;
string='Your'||'05'x||'data'||'0D'x||'goes'||'0C'x||'here.'||'0A'x;
run;
data _null_;
set sample;
put string=;
/* Verify each byte in string until no more non-printables are found */
do until(test=0);
/* For SAS 9.0 and above, NOTPRINT */
test=notprint(string);
/* prior to SAS 9.0, use VERIFY */
*test=verify(upcase(string),' ABCDEFGHIJKLMNOPQRSTUVWXYZ,.1234567890');
/* If a non-printable is found...replace it with a space */
if test>0 then do;
substr(string,test,1)=' ';
end;
end;
put 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 remove non-printable
characters from character variables.
| 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 | |