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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.