BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
raveena
Obsidian | Level 7

Hi,

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.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

;

View solution in original post

8 REPLIES 8
FriedEgg
SAS Employee

compress(vendor,,'adk');

art297
Opal | Level 21

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

;

FriedEgg
SAS Employee

data foo;

informat vendor $30.;

input vendor & $30.;

if notalnum(strip(vendor))=0;

cards;

111948722-070Ž

1119789^78A

789567890

908765TYR

;

run;

art297
Opal | Level 21

FE, That wouldn't correctly handle an entry like 908765-TYR

FriedEgg
SAS Employee

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

art297
Opal | Level 21

The OP considered a dash as a valid character.

FriedEgg
SAS Employee

That's what I get for skimming the post.

Ksharp
Super User
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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 4830 views
  • 3 likes
  • 4 in conversation