DATA Step, Macro, Functions and more

treating '-' as part of the word

Accepted Solution Solved
Reply
Regular Contributor
Posts: 234
Accepted Solution

treating '-' as part of the word

The last name from following code is only "Anne". I want "Anne-marie" as last name.

 

data test;
  name='Jen Anne-marie';
  first_name=scan(name,1);
  last_name=scan(name,2);
run;

Accepted Solutions
Solution
‎01-28-2016 11:39 AM
Super Contributor
Posts: 490

Re: treating '-' as part of the word

data test;
  name='Jen Anne-marie';
  first_name=scan(name,1);
  last_name=scan(name,2," ");
run;

View solution in original post


All Replies
Super User
Posts: 17,868

Re: treating '-' as part of the word

Solution
‎01-28-2016 11:39 AM
Super Contributor
Posts: 490

Re: treating '-' as part of the word

data test;
  name='Jen Anne-marie';
  first_name=scan(name,1);
  last_name=scan(name,2," ");
run;
Super User
Posts: 17,868

Re: treating '-' as part of the word

Or the 4th parameter.

 

data test;
  name='Jen Anne-marie';
  first_name=scan(name,1);
  last_name=scan(name,2,,'s');
run;

proc print; run;
Regular Contributor
Posts: 234

Re: treating '-' as part of the word

@ Reeza, I wrongly thought space as one of the default delimiters, that's why I did not provide third parameter.
Super User
Posts: 17,868

Re: treating '-' as part of the word

It is the default delimiter, but only one of them. 

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 226 views
  • 4 likes
  • 3 in conversation