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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

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
  • 1360 views
  • 0 likes
  • 5 in conversation