BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Quentin
Super User

@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.

Hello_there
Lapis Lazuli | Level 10
Thanks for your help, Quentin!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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
  • 16 replies
  • 3667 views
  • 4 likes
  • 4 in conversation