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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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