08-30-2011 09:04 AM
I have a list of values which have '_STD' appended to the end of them. I need to remove this suffix so that I am left with just the beginning part
name= SAW_PRICE_STD want SAW_PRICE
I tried the compress function but doesn't seem it can compress out strings, only charachters. I tried somehting like
name2=compress(name, "_STD") but it gives me 'AWPRICE'
Is there a function which can remove whole strings? or a solution to the above. Could use tranwrd but would be good to know if what I am looking for is already available in one function
Help greatfully appreciated
08-30-2011 09:25 AM
Hi again Art
Thanks for this, but doesn't seem to be there for 9.1.3..wich is what i am working on. Is it a 9.2 function?
I got around it using
but would be good to know if there is a function for 9.1.3 which will do what transtrn does. Or even to strip strings out.
Ps sorry not got back to you on another post you wrote. It's a lot of code to go through at the moment for me and looks like some new stuff for me in there. Will try Art, hopefully. It is on the radar but drifting out of view. Sorry
08-30-2011 02:54 PM
Hi ... you got an answer from Art, but given that you tried ...
here's another function idea. Just make the format in the PUT statement 4 less than the length of NAME
input name $20.;
name = left(put(right(name),$16.));
proc print data=x;
08-30-2011 03:14 PM
The problem with TRANWRD is that it will replace all instances in the string. So X_STD_Y_STD would become X_Y.
You might want to test that _STD are the last four characters of the name.
if reverse('_STD') =: reverse(trim(name)) then ...
if scan(name,-1,'_') = 'STD' then
08-30-2011 11:24 PM
Function substr() would be helpful.
data x; input name $20.; datalines; SAW_PRICE_STD XYZ_STD MIKE_STD ABCDEFGHI_STD ; run; data want; set x; new=substr(name,1,length(name)-4); run;
08-31-2011 12:56 AM
Good suggestions and things to consider..and learn
_STD only occurs once in the names..so they say ;-) .. so may be an option to use a conditioning if statement with the tranwrd function or something like what Ksharp and MikeZDeb said. Or somthing else..but cheers for the replies..so many options when once there was none!
08-31-2011 02:41 AM
data x; input name $20.; datalines; SAW_PRICE_STD XYZ_STD MIKE ABCDEFGHI ; run; data want; set x; new=substr(name,1,ifn(find(name,'_STD'),find(name,'_STD')-1,length(name)) ); run;
09-01-2011 08:54 AM
Just to let you know I went for:
*--- check that the last 4 charachters are 'STD_';
if left(reverse(name))=: 'DTS_'
Cheers for all your suggestions
09-07-2011 03:35 AM
input name $20.;
I'm really learning to like the PRX* functions...
Need further help from the community? Please ask a new question.