BookmarkSubscribeRSS Feed
AaroninMN
Obsidian | Level 7
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.
3 REPLIES 3
deleted_user
Not applicable
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.
AaroninMN
Obsidian | Level 7
Thank You. For some reason I thought I needed to use substring and trim.
Doc_Duke
Rhodochrosite | Level 12
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).

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1269 views
  • 0 likes
  • 3 in conversation