BookmarkSubscribeRSS Feed
Allihaveneed892
Calcite | Level 5

Here i Need a solution for below problem. i need output should be like 25.45 only that to be by using string functions.

 

data ex1 ;

mynumber=25.45789;

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Why do you want to use only string functions?

Allihaveneed892
Calcite | Level 5
because its a TASK to me. but i couldn't find solution

Tom
Super User Tom
Super User

So you have a character string and you just want to take the first 5 characters? 

 

Use substr().

data have;
  string='25.45789';
  new_string=substr(string,1,5);
run;

If the actual request is not to just take the first 5 character then please explain the rule more completely.

 

Also why did you call the variable MYNUMBER if you want it to be a character variable?

Kurt_Bremser
Super User

So this task is meant to test your skills, not ours 😉

What is the actual rule? Take the first 5 characters, or reduce to 2 fractional digits, with or without rounding?

tarheel13
Rhodochrosite | Level 12

is mynumber numeric? if it's numeric, then you can do strip(put(mynumber,8.2)).