@Hello_there wrote:
How would i be able to vary the round function between 0 to 3 decimal places?
You can use another call to RAND to generate the integers 0-3, and then use that as an input to the ROUND function, e.g.:
data have(keep=group val places val2);
a=-5; b=5;
do i=1 to 100;
do group="grp1", "grp2", "grp3";
u=rand("Uniform");
val=a+(b-a)*u;
places = rand("Integer", 0, 3);
val2=round(val,10**(places*-1)) ;
output;
end;
end;
run;
proc print data=have ;
run ;
Note that as mentioned when you PRINT the rounded data you won't see values varying number of places, because SAS is still storing them all as numbers. If you want to actually see values with varying number of places, you might want to consider converting this variable to character. But it all depends on what your macro is designed to do.
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.