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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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