BookmarkSubscribeRSS Feed
_sas
Calcite | Level 5

Hello Everyone,

 

I want 100.10 as a value of variable e. is it possible without using any format ?

 

data _null_;

b="100.1";
c=input(b,5.2);

d="100.10";
e=input(b,6.2);

put _all_;
run;

 

Capture.PNG

3 REPLIES 3
Astounding
PROC Star

No, it's not possible.  Numbers do not contain a set of characters in SAS.  Numbers store a numeric value, not the form in which it is expressed.  You can always add a FORMAT statement later, when printing the numeric variable.

 

Just for the record, your INPUT functions are treading on dangerous ground.  You would be safer using:

 

b="100.1";
c=input(b,5.);

d="100.10";
e=input(b,6.);

 

To see why, try this (and read the documentation):
 

b="12345";
c=input(b,5.2);

Kurt_Bremser
Super User



@_sas wrote:

Hello Everyone,

 

I want 100.10 as a value of variable e. is it possible without using any format ?

 



SAS data step being turing-complete, it is of course possible. See here:

data test;
have = '100.10';
want = 0;
fr_count = .;
do i = 1 to length(have);
  if substr(have,i,1) = '.'
  then fr_count = 0;
  else do;
    want = want * 10 + rank(substr(have,i,1)) - 48;
    if fr_count ne . then fr_count + 1;
  end;
end;
if fr_count ne . then want = want / 10 ** fr_count;  
run;

Note that I did this because sometimes I have enough time at hand to waste on stupid ideas 😉

Ksharp
Super User
data _null_;

b="100.1";
c=b+0;


put _all_;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 754 views
  • 3 likes
  • 4 in conversation