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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.