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?
proc print data = have;
var namevar;
where prxMatch("/ ,|, /", namevar);
run;
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},
proc print data = have;
var namevar;
where prxMatch("/ ,|, /", namevar);
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.