SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ilikesas
Barite | Level 11

Hi,

 

suppose I have the following table PARMS:

parameter esimate
a 14.72344
b -0.00015
c 0.74911
d -0.00986

 

using the round function I rounded each value to 3 decimal places and got the following table PARMS2:

 

data parms2;
set parms;
estimate= round(estimate,.001); 
run;
parameter estimate
a 14.72300
b 0
c 0.74900
d -0.01000

 

Now I want to get rid of the extra zeroes - I want to leave only the integer part and the first 3 decimals. I thought just getting rid of the 2 right-most numbers using the following code:

 

data parms3;
set parms2;
estimate=substr(estimate,1,length(estimate)-2);
run;

 

But the result PARMS3 is a mess:

 

parameter estimate
a 14.70000
b .
c 0.70000
d 0

 

Could you please help me?

 

Thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

SUBSTR is intended for characters you have a numeric variable.

 

Why not use a format instead?

 

format estimate 12.3;

View solution in original post

2 REPLIES 2
Reeza
Super User

SUBSTR is intended for characters you have a numeric variable.

 

Why not use a format instead?

 

format estimate 12.3;
ballardw
Super User

Note that using a format like 12.3 can remove the need for a separate rounding step and may prevent some odd behaviors involving multiple rounding.

Please see:

data _null_;
   x= 123.78445;
   r1=round(x,0.0001);
   r2 = round(r1,0.001);
   r3 = round(r2,0.01);
   put x= 12.4 r1= x=12.3 r2= x=12.2 r3=;
run;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1727 views
  • 1 like
  • 3 in conversation