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
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 |
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
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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.