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).

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1187 views
  • 0 likes
  • 3 in conversation