I request someone guide me to remove the records which contains special characters.
data Have:
+1234
123 4
12-3
1234
data want:
1234
Look at using a DATA step to INPUT your data-records, then test using one of the appropriate ANY-prefix SAS functions found in the SAS Language Elements / CALL function documentation. A tip is that you can use _INFILE_ as the argument passed to your function call, although it is unclear if you want to create an output file (non-SAS) or a SAS data library member based on your input -- that would determine whether or not a FILE statement is warranted as opposed to a SAS member on your DATA statement, instead of DATA _NULL_;
Scott Barry
SBBWorks, Inc.
Hi,
Compress. If you want on a single result from them, then sort nodupkey.
new_variable=compress(old_variable,,'kd');
My real data looks like,
data Have:
+1234
213 0
782-3
1239
data want:
1239
In this case how to dealt with compress function? Any other functions to look for?
data want;
set have;
if length(strip(compress(the_string,,'d'))) = 0 then output;
run;
I.e. if I remove all numbers, and length is zero, there is nothing other than numbers.
That's a good approach, but it needs a little tweaking on two counts. First, STRIP isn't needed. Leading and trailing blanks don't need to be removed if you only want to detect whether any characters remain. Second, LENGTH has a quirk: it never returns zero. The minimum value returned is 1. The easiest way to overcome this is to switch to LENGTHN:
if lengthn(compress(the_string,,'d'))=0 then output;
data Have;
input num $6.;
if prxmatch('/^\d{4}/o',strip(num))^=0 then output;
cards;
+1234
213 0
782-3
1239
;
run;
data Have;
input num $20.;
if not prxmatch('/\D/',strip(num)) then output;
cards;
+1234
213 0
782-3
1239
;
run;
data Have;
input num $20.;
if not notdigit(strip(num)) then output;
cards;
+1234
213 0
782-3
1239
;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.