BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tapas_16880
Calcite | Level 5

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...

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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'

View solution in original post

7 REPLIES 7
Reeza
Super User

substr(prod_ind, 1, length(prod_ind)-1);

MikeZdeb
Rhodochrosite | Level 12

hi ... lots of ways to do this ...

prod_ind = putc(prod_ind,catt('$',length(prod_ind)-1));

substr(prod_ind,length(prod_ind)) = ' ';

tapas_16880
Calcite | Level 5

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?

Patrick
Opal | Level 21

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'

tapas_16880
Calcite | Level 5

thanks all for the help and suppport!!! Appreciated...

LittlesasMaster
Obsidian | Level 7

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

    
1ABC
2aaaaa
3sdfasf
4sswgerg
5sgswgrr
6sgwrg
7fawef
8sg
93erq
10sg
11dfb
12dfb
13sffggggg
14ergerg

Thanks!!

Ksharp
Super User

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 88054 views
  • 8 likes
  • 6 in conversation