I have a dataset with vendor number containing invalid characters.I would not select any vendor numbers that contain characters other than A-Z,0-9 or dash(-).We can use compress function, but not sure what are the invalid characters in the data.
Example:
data test;
input vendor ;
cards;
111948722-070Ž
1119789^78A
789567890
908765TYR
;
RUN;
REQUIRED OUTPUT :
Vendor
789567890
908765TYR
Please let me know.
Thanks in Advance.
Sort of like FE's suggestion, but because 'a' will accept non-English characters, I'd suggest the following to limit it to only English characters. However, this assumes that underscores are also valid for your purpose. Otherwise, one additional check would be needed:
data test;
informat vendor $30.;
input vendor &;
if compress(vendor,'-','dfk') eq vendor;
cards;
111948722-070Ž
1119789^78A
789567890
908765TYR
;
compress(vendor,,'adk');
Sort of like FE's suggestion, but because 'a' will accept non-English characters, I'd suggest the following to limit it to only English characters. However, this assumes that underscores are also valid for your purpose. Otherwise, one additional check would be needed:
data test;
informat vendor $30.;
input vendor &;
if compress(vendor,'-','dfk') eq vendor;
cards;
111948722-070Ž
1119789^78A
789567890
908765TYR
;
data foo;
informat vendor $30.;
input vendor & $30.;
if notalnum(strip(vendor))=0;
cards;
111948722-070Ž
1119789^78A
789567890
908765TYR
;
run;
FE, That wouldn't correctly handle an entry like 908765-TYR
Art,
I tested and it works for me?
NOTALNUM should provide value >0 for any character that is not a letter or digit.
data foo;
informat vendor $30.;
input vendor & $30.;
if notalnum(strip(vendor))=0;
cards;
111948722-070Ž
1119789^78A
789567890
908765TYR
908765-TYR
;
run;
789567890
908765TYR
The OP considered a dash as a valid character.
That's what I get for skimming the post.
data test; informat vendor $30.; input vendor &; if not findc(strip(vendor),'-','duk'); cards; 111948722-070^ 1119789^78A 789567890 908765TYR ; run;
Ksharp
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 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: