Remove last chars

Accepted Solution Solved
Reply
Regular Contributor
Posts: 212
Accepted Solution

Remove last chars

Hi,

I'm having troubles with substr() function.

I have a data set that has a column likes this:

var1

213

100

234

235

124

200

400

500

It is a char column and i need to remove last two "00"

But without removing the from the others.

I've tried to do this:

if substr(var1,2,2)="00" then new_var = substr(var1,1,1);

else new_var = var1;

But this didn't work.

Thanks Before anything

Rodrigo Dartibali


Accepted Solutions
Solution
‎08-17-2015 12:23 PM
Contributor
Posts: 65

Re: Remove last chars

Posted in reply to DartibaliRodrigo

data a;

input a $;

if substr(a,2,2)="00" then a=substr(a,1,1);

cards;

213

100

234

235

124

200

400

500

;

View solution in original post


All Replies
Solution
‎08-17-2015 12:23 PM
Contributor
Posts: 65

Re: Remove last chars

Posted in reply to DartibaliRodrigo

data a;

input a $;

if substr(a,2,2)="00" then a=substr(a,1,1);

cards;

213

100

234

235

124

200

400

500

;

Regular Contributor
Posts: 212

Re: Remove last chars

Posted in reply to DartibaliRodrigo

Solved, Thanks.

Respected Advisor
Posts: 3,799

Re: Remove last chars

Posted in reply to DartibaliRodrigo

Is VAR1 numeric or character?

Are you seeing a note that numeric values were converted to character?

Your code does work if VAR1 is character and left justified in the field of 3 or more.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 187 views
  • 2 likes
  • 3 in conversation