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

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 885 views
  • 0 likes
  • 5 in conversation