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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 364 views
  • 2 likes
  • 4 in conversation