The SUBSTR function is the first of the various character functions we demonstrate.A brief review is in order. A "string" in computer parlance is a collection of characters that are assigned to a variable.For example,a character variable called ID could have a value of 427NJ or 12345. Notice that a character string may consist solely of numerals as long as it has been declared as a character variable to the program. Suppose you have ID's of length 5,and the last two characters represent a state code (such as 427NJ above).Data set OLD,following, contains some sample ID's:Data Set OLD
Here is a program to extract the state code from the ID:
The values for STATE are N J and NY in this example.
The general form of the substring function is:
SUBSTR (char_variable,starting_position, length);
The char_yariable can also be a character expression or a character constant.It is a good idea to use a LENGTH statement to assign a length to the substring variable as is done here.The dollar sign in the LENGTH statement indicates that STATE is a character variable and the 2 indicates its length.If you don't take the trouble to do this,the length of the substring is the same as the length of the variable from which you are extracting the substring.This is both wasteful and potentially dangerous in that it can lead to erroneous results.
SAS Programming Related Tutorials
|SASS (Syntactically Awesome Style sheets) Tutorial||R Programming language Tutorial|
SAS Programming Related Interview Questions
|Logistics Interview Questions||SAS Programming,SQL server Interview Questions|
|Clinical SAS Interview Questions||SASS (Syntactically Awesome Style sheets) Interview Questions|
|SQL Server Analysis Services (SSAS) Interview Questions||R Programming language Interview Questions|
|SAS DI Interview Questions||Advanced SAS Interview Questions|
|Base Sas Interview Questions||SAS Macro Interview Questions|
|Clinical Data Management Interview Questions|
Sas Programming Tutorial
Input And Infile
Set, Merge, And Update
Table Lookup Tools
Proc Means And Proc Uimivariate
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.