Hi Guys,
I have a SAS file and one of its columns has values like this:
column : PROD_IND
value:
ABC+
aaaaa+
sdfasf+sswgerg+sgswgrr+sgwrg+
fawef+sg+3erq+sg+dfb+dfb+
sffgggggghhhhh+
ergerg+
dfw+rg+gergh+eth+rth+hrth+
.
.
.
I just want to delete the last '+' from these values. All the values have got a '+' as the last character. I want to delete that keeping the earlier ones.
I have tried substr and compress and index... not having luck.
Please help...
Suggest you mark answered questions as answered giving the "points" to the ones deserving them and then ask consecutive questions in a new thread referencing to the old one.
But to answer your follow up question:
I assume you have leading blanks in front of your ABC string. A "like" will find any occurence of ABC in a string, eg. xxxxABCyyyy. If you just want to find ABC but don't care about leading blanks then use where strip(PROD_IND) = 'ABC'
substr(prod_ind, 1, length(prod_ind)-1);
hi ... lots of ways to do this ...
prod_ind = putc(prod_ind,catt('$',length(prod_ind)-1));
substr(prod_ind,length(prod_ind)) = ' ';
Thanks for the help... Need another help similar to this...
Same column that has now:
ABC
aaaaa+ dfg
sdfasf+sswgerg+sgswgrr+sgwrg
fawef+sg+3erq+sg+dfb+dfb
sffgggggghhhhh
ABC
xyz+qwe
ergerg
dfw+rg+gergh+eth+rth+hrth
because I have removed the last '+' symbol from this column.
Now, I need to find whenever the value is ABC and no '+' in it, then set a FLAG to 'Y'
I dont know why but when I am doing -
proc sql;
create table ddd as
select * from xyz where PROD_IND = 'ABC';quit;
this doesn't select any record but when I am using LIKE '%ABC%' then it is retrieving records.
Not sure why....
Do u have any other way to achieve this?
Suggest you mark answered questions as answered giving the "points" to the ones deserving them and then ask consecutive questions in a new thread referencing to the old one.
But to answer your follow up question:
I assume you have leading blanks in front of your ABC string. A "like" will find any occurence of ABC in a string, eg. xxxxABCyyyy. If you just want to find ABC but don't care about leading blanks then use where strip(PROD_IND) = 'ABC'
thanks all for the help and suppport!!! Appreciated...
Hey Tapas,
I just wanted to share a simplest method to remove the last char of any string, this is amazing and working perfectly for me.
data test;
input ur_string$;
ur_string=scan(ur_string,-1);
cards;
ABC+
aaaaa+
sdfasf+
sswgerg+
sgswgrr+
sgwrg+
fawef+
sg+
3erq+
sg+
dfb+
dfb+
sffgggggghhhhh+
ergerg+
;
run;
proc print;
run;
OUTPUT:
The SAS System |
1 | ABC |
---|---|
2 | aaaaa |
3 | sdfasf |
4 | sswgerg |
5 | sgswgrr |
6 | sgwrg |
7 | fawef |
8 | sg |
9 | 3erq |
10 | sg |
11 | dfb |
12 | dfb |
13 | sffggggg |
14 | ergerg |
Thanks!!
Didn't you notice there are some '+' in the string ? Your code isn't going to work at this situation. Perl Regular Expression is the most simplest ,powerful,flexible method for such question.
data test;
input ur_string $40.;
string=prxchange('s/\++$//',-1,strip(ur_string));
cards;
ABC+
aa+aaa+
sdfasf+
sswgerg+
sgswgrr+
sgwrg+
fawef+
sg+
3erq+
sg+
dfb+
dfb+
sffgggggghhhhh+
ergerg+
;
run;
proc print;
run;
Xia Keshan
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.