My code returns unexpected result as follows:
x = index(lowcase(security_name), lowcase("alltel communications"));
x2 = index(lowcase(security_name), lowcase(name_holding_clean));
Shouldn't x=x2? My guess is that it's related to the length of name_holding_clean, but not sure how to deal with it.
Most of the functions such as LOWCASE when used as a parameter to another function return the result padded with blanks to length of the variable.
Try
x2 = index(lowcase(security_name), strip( lowcase(name_holding_clean) ) );
Most of the functions such as LOWCASE when used as a parameter to another function return the result padded with blanks to length of the variable.
Try
x2 = index(lowcase(security_name), strip( lowcase(name_holding_clean) ) );
You are right, thanks!
Why LOWCASE does not pad with blanks when the I copy the string, instead of using a variable as input?
It takes the length of the source you supply. With a literal, it is the length of the string as written, with a variable, the defined length of the variable.
Note that the LOWCASE() function calls has nothing to do with this issue.
SAS stores character variables as fixed length. If you assign a value that is shorter than the max then it is padded with spaces. If you assign a value that is longer it is truncated.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.