- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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...
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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'
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
substr(prod_ind, 1, length(prod_ind)-1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
hi ... lots of ways to do this ...
prod_ind = putc(prod_ind,catt('$',length(prod_ind)-1));
substr(prod_ind,length(prod_ind)) = ' ';
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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'
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thanks all for the help and suppport!!! Appreciated...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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