Sample 39036: Eliminating duplicate characters in a string
/* for the purpose of this sample, we're not creating a data set */
data _null_;
/* read data from DATALINES */
input string $ 1-20;
/* examine the beginning value */
put 'Before ' string=;
/* capture the number of characters in the variable */
l1=length(string);
/* the loop below captures each character in turn and compares
the remaining characters by position. If a match is found,
the matching value is replaced with a null character, '00'x.
If the first value is a null character, the comparison loop
is not executed. */
do i = 1 to l1-1;
t1=substr(string,i,1);
if t1 ^= '00'x then do j = i+1 to l1;
if t1=substr(string,j,1) then substr(string,j,1)='00'x;
end;
end;
/* the COMPRESS function is used to remove the nulls*/
string=compress(string,'00'x);
/* this is to view the variable after alteration. */
put 'After ' string= /;
drop l1 t1 i j ;
datalines;
QWERTQWERT
AASSDDFFGG569
;
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.
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.
This code sample will remove duplicate characters from a character string, concatenate, and left justify the remaining characters.
Date Modified: | 2010-06-25 13:02:12 |
Date Created: | 2010-03-15 12:59:52 |
Operating System and Release Information
SAS System | N/A | OpenVMS Alpha | | |
Linux for x64 | | |
Linux on Itanium | | |
Linux | | |
IRIX | | |
HP-UX | | |
HP-UX IPF | | |
AIX | | |
ABI+ for Intel Architecture | | |
64-bit Enabled Solaris | | |
64-bit Enabled HP-UX | | |
64-bit Enabled AIX | | |
Windows Vista | | |
Windows Millennium Edition (Me) | | |
Windows 7 Ultimate x64 | | |
Windows 7 Ultimate 32 bit | | |
Windows 7 Professional x64 | | |
Windows 7 Professional 32 bit | | |
Windows 7 Home Premium x64 | | |
Windows 7 Home Premium 32 bit | | |
Windows 7 Enterprise x64 | | |
Windows 7 Enterprise 32 bit | | |
Microsoft Windows XP Professional | | |
Microsoft Windows Server 2008 | | |
Microsoft Windows Server 2003 Standard Edition | | |
Microsoft Windows Server 2003 Enterprise Edition | | |
Microsoft Windows Server 2003 Datacenter Edition | | |
Microsoft Windows NT Workstation | | |
Microsoft Windows 2000 Server | | |
Microsoft Windows 2000 Datacenter Server | | |
Microsoft Windows 2000 Advanced Server | | |
OS/2 | | |
Microsoft Windows 95/98 | | |
Microsoft® Windows® for x64 | | |
Microsoft Windows XP 64-bit Edition | | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | | |
Microsoft Windows 2000 Professional | | |
Macintosh on x64 | | |
Macintosh | | |
OpenVMS VAX | | |
z/OS | | |
OpenVMS on HP Integrity | | |
Solaris | | |
Solaris for x64 | | |
Tru64 UNIX | | |