05-01-2014 10:09 AM
I was give a bunch of data sets that have been reworked to include a prefix on the variable name. I have a loop written to remove the prefix but the problem I'm encountering is the compress function is removing all characters within the prefix from the var name. I'd like it to remove the specific sequence of the letters and not all the letters. Is it possible to do this?
The prefix in all of these example is "INF_"
Not all of the variables in the data set have the prefix, that is why I've attempted to do this using the compress function.
05-01-2014 10:25 AM
Yep, just be careful though as if you have INF_INFO and you do a tranwrd(...,'INF','') then you would end up with _O. If you know the prefix is INF_ first three characters, it could be beneficial to use substr, e.g. if substr(...,1,4)='INF_' then ...=substr(...,4);
05-01-2014 12:39 PM
Use the TRANSTRN() function to replace the string INF_ with nothing.
desired_result = transtrn(input,'INF_',trimn(' '));
Of if you know the values are always at the beginning of the string then use SUBSTR.
desired_result = input ;
if desired_result =: 'INF_' then desired_result = substr(desired_result,5) ;