From the course: SAS® 9.4 Cert Prep: Part 10 Manipulating Data with Functions

Unlock this course with a free trial

Join today to access over 22,700 courses taught by industry experts.

Extracting words from a string

Extracting words from a string

- [Tutor] Next let's take a look at the location column and the precipitation data. This column includes uppercase city, the prefecture and the country code. Suppose we want to pass this information to create separate columns for city and prefecture. The scan function is a great way to extract a particular word in a sequence from a string. You simply provide a character column as the first argument and the word number you want to extract as the second argument. The optional third argument enables you to control the characters that are treated as delimiters indicating when words begin and end. To extract the name of the city from location you can use the scan function to read location and extract the first word. By default SAS uses the default delimiter list. So each of these characters indicates the end of one word and the beginning of the next word.

Contents