BookmarkSubscribeRSS Feed
raja777pharma
Fluorite | Level 6

Hi Team,

 

I would like to check whether possible to pass the variable value as the second argument in round function.

please help me how to pass the VAR2,VAR3 and VAR4 values in round function.

 

My data;

VAR1                VAR2          VAR3   VAR4

23.453472        0.1              0.01     0.001

 

My code:

new_var = round(VAR1,VAR2);

new_var1=round(VAR1,VAR3);

new_var2=round(VAR1,VAR4);

 

Thank you,

Rajasekhar 

 

 

 

3 REPLIES 3
SASJedi
SAS Super FREQ

There is nothing wrong with that syntax - it works just fine:

data have;
	input VAR1 VAR2 VAR3 VAR4;
datalines;
23.453472  0.1  0.01 0.001
; 

data want;
	set have;
	new_var = round(VAR1,VAR2);
	new_var1=round(VAR1,VAR3);
	new_var2=round(VAR1,VAR4);
run;

Results:

VAR1 VAR2 VAR3 VAR4 new_var new_var1 new_var2
23.4535 0.1 0.01 .001 23.5 23.45 23.453
Check out my Jedi SAS Tricks for SAS Users
sbxkoenk
SAS Super FREQ

Hello,

 

When you wonder if something is possible, just try it out.
In this case : there's no problem whatsoever !

 

data have;
VAR1=23.453472;
VAR2=0.1;
VAR3=0.01;
VAR4=0.001;
new_var =round(VAR1,VAR2);
new_var1=round(VAR1,VAR3);
new_var2=round(VAR1,VAR4);
run;

Koen

ballardw
Super User

Depending the values of your second variable you may not immediately recognize that the Round worked as used though. SAS Round function doesn't complain about rounding to the nearest 6.07 for example.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 3 replies
  • 626 views
  • 2 likes
  • 4 in conversation