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

Hi there,

I need your kind help to detect one column having any special characters with or without dot, apostrophe, hyphen and comma. If it contains only dot, apostrophe, hyphen or comma, I don't want to flag. 

data have;
input  name $;
datalines;
abc
def_
def-ghi
def's
def.
def@ghi.ijk
def-ghi&ijk
def%
;
run;

I want to flag the following:

def_

def@ghi.ijk
def-ghi&ijk
def%

 

Thank you in advance for your kind reply.

Regards,

 

 

Swain
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

What is your definition of special?  All of the strings you posted have characters other than the ones you listed.  Did you mean to allow normal alphanumeric characters?

 

data want ;
   set have;
   flag=' '^=compress(name,".',-",'ad');
run;
proc print;
run;
Obs    name           flag

 1     abc              0
 2     def_             1
 3     def-ghi          0
 4     def's            0
 5     def.             0
 6     def@ghi.ijk      1
 7     def-ghi&ijk      1
 8     def%             1

View solution in original post

4 REPLIES 4
ballardw
Super User

You may want to provide an explicit definition of "special characters". I don't believe that there is an actual standard definition. I know I have issues with various password rules and they have different lists of special characters that are acceptable or refused.

This might get you started. It should be easy to add or remove suspect characters though a " as done will be a bit trickier.

data have;
input  name $;
flag = findc(name,"!@#$%^&*()_+=",'')>0;
datalines;
abc
def_
def-ghi
def's
def.
def@ghi.ijk
def-ghi&ijk
def%
;
run;
DeepakSwain
Pyrite | Level 9

Hi Ballardw,

 

The suggested advice is great. Only limitation with this to provide a list of special characters of interest to flag.

I am trying to use ANYPUNCT function but unable to apply my exclusion list i.e. dot, aposytrophe, hypen and comma. 

Can you kindly help me if feasible to use anypunct function so the code may be generalized. 

Once again thank you for your kind reply.

Regards,

Swain
ballardw
Super User

ANYPUNCT will not work as several of the characters you appear to want flagged such a & and @ (note: asked for definition of "special character" ) are not punctuation characters.

 

 

Tom
Super User Tom
Super User

What is your definition of special?  All of the strings you posted have characters other than the ones you listed.  Did you mean to allow normal alphanumeric characters?

 

data want ;
   set have;
   flag=' '^=compress(name,".',-",'ad');
run;
proc print;
run;
Obs    name           flag

 1     abc              0
 2     def_             1
 3     def-ghi          0
 4     def's            0
 5     def.             0
 6     def@ghi.ijk      1
 7     def-ghi&ijk      1
 8     def%             1

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1552 views
  • 3 likes
  • 3 in conversation