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

Hi,

 

I have a name variable where most values are Last, First. 

 

I want to examine records where the name value contains two blanks followed by a comma OR a comma followed by two blanks (ie, the comma has two blanks on at least one side). This is what I have set up:

 

proc print data = have;

    var namevar;

    where index(namevar, ',')>0 and (index(namevar, '  ,') >0 or index(namevar, ',  ')>0));

run;

 

The step ran but did not produce what I thought it would. I didn't see what I was looking for: a double blank followed by a comma, or a comma followed by a double blank. Instead I only saw one or zero blanks adjacent to the columns.

 

Should this be working? If not, is there a different approach?

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21
proc print data = have;
var namevar;
where prxMatch("/  ,|,  /", namevar);
run;
PG

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Hi @Walternate   Try Regex. A sample data for us to play with would have been nice.

For two blanks followed by a comma

Regex would be : \s (any white space)  quantifier needed is 2 , so regex {2} followed by a comma ,

Something like the below

\s{2}, 

 

 

PGStats
Opal | Level 21
proc print data = have;
var namevar;
where prxMatch("/  ,|,  /", namevar);
run;
PG

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 2 replies
  • 446 views
  • 0 likes
  • 3 in conversation