Desktop productivity for business analysts and programmers

Data left of a space

Reply
Occasional Contributor
Posts: 15

Data left of a space

How do I get only data left of a space.
Ex. If the field was Jean Pierre and I only wanted Jean to be returned?

Also is there a way to do this when the space is in different positions such as space 6 or 8?

Thanks in advance.
N/A
Posts: 0

Re: Data left of a space

SCAN is SAS's tokenizer function.
[pre]
data test_this;
sentence = "The quick brown fox jumped over the lazy dog";
first_word = scan(sentence,1," ");
last_word = scan(sentence, -1, " ");

log_string = "2008-04-29 14:55 | application | method | WARNING -- ... " ;
time_string = scan(log_string, 1, "|" );
run;
quit;

proc print;
run;
quit;
[/pre]

So, read about the SCAN function in the SAS documentation.
Occasional Contributor
Posts: 15

Re: Data left of a space

Thank You. For some reason I thought I needed to use substring and trim.
Valued Guide
Posts: 2,111

Re: Data left of a space

SCAN is a relatively new function. INDEX and SUBSTR are older tools that could be used to the same effect (but with a lot more effort).
Ask a Question
Discussion stats
  • 3 replies
  • 132 views
  • 0 likes
  • 3 in conversation