What Is The SAS Equivalent Of The LEFT Function In Excel?
By Alan Hylands — 1 minute read
I see an awful lot of hate for Excel on Data Science and Business Intelligence forums and blogs but there is a very good reason why it is the world’s number one most used business tool: it’s bloody easy to get started.
Moving beyond that for Excel jockeys then can be a bit of a steep learning curve when so many handy functions had previously been at their fingertips.
One often used function is the LEFT function.
In Excel this allows us to isolate and strip out a specified number of characters from the left hand side of a text string
e.g. =LEFT(“Alan Hylands”, 4) would give us the following result:
In SAS, we can use the SUBSTR function in the data step to replicate this.
SUBSTR(“Alan Hylands”,1,4) would give us the same result (where the first argument is the text string (“Alan Hylands”), the second is the character to start at (character #1) and the third is the number of characters to look at (4 characters) .