DATA Step, Macro, Functions and more

treating '-' as part of the word

Accepted Solution Solved
Reply
Super Contributor
Posts: 271
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

Posted in reply to SAS_inquisitive
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: 19,770

Re: treating '-' as part of the word

Posted in reply to SAS_inquisitive
Solution
‎01-28-2016 11:39 AM
Super Contributor
Posts: 490

Re: treating '-' as part of the word

Posted in reply to SAS_inquisitive
data test;
  name='Jen Anne-marie';
  first_name=scan(name,1);
  last_name=scan(name,2," ");
run;
Super User
Posts: 19,770

Re: treating '-' as part of the word

Posted in reply to SAS_inquisitive

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;
Super Contributor
Posts: 271

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: 19,770

Re: treating '-' as part of the word

Posted in reply to SAS_inquisitive

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
  • 227 views
  • 4 likes
  • 3 in conversation