Search for a hyphen from the first name only

If I have a dataset containing many names, such as "Steve Jobs", how can I search for names that have a hyphen in the first name only using the proc print command?

Example: Dataset ex1 contains

name
 --------
Steve Jobs
Steve Job-s <- I do not want this
Ste-ve Jobs <- I want this

      

The code I have written is the following

proc print data=ex1 noobs split=' ';    
    where name like '%-%';
run;

      

My code will print "Steve Job-s" and "Ste-ve Jobs". What can I do to stop "Ste-ve Jobs"?

+3


source to share


1 answer


Use the function scan()

to check only the first word for your condition. The third argument specifies a space as a separator; this is necessary as it is otherwise -

included in the default delimiters:



where scan(name,1,' ') like '%-%';

      

+3


source







All Articles