SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kmardinian
Quartz | Level 8

Hi, If I would like to round up or down for a specific variable in a dataset under these two conditions, what would be the best/easiest way to do this in SAS?

 

For decimal value outcomes < X.5, round down to the nearest integer

For decimal value outcomes ≥ X.5, round up to the nearest integer

 

I've seen it done as a do loop, but that seems overly complicated.

 

Any help is much appreciated, thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

This is exactly what the Round Function does?

 

data have;
   do x=1 to 10;
      y=x*rand('uniform');
      output;
   end;
run;

data want;
   set have;
   z=round(y);
run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

This is exactly what the Round Function does?

 

data have;
   do x=1 to 10;
      y=x*rand('uniform');
      output;
   end;
run;

data want;
   set have;
   z=round(y);
run;
ballardw
Super User

And for extra added fun you can actually round to the nearest multiple of a given number. The default is 1 if not supplied.

 

data have;
   do x=1 to 10;
      z= rand('uniform');
      y1= round(x*z,1);
      y2= round(x*z,2);
      y3= round(x*z,.7);
      y4= round(x*z,2.5);
      output;
   end;
run;
PaigeMiller
Diamond | Level 26

@kmardinian wrote:

For decimal value outcomes < X.5, round down to the nearest integer

For decimal value outcomes ≥ X.5, round up to the nearest integer


This is different than the title of this thread, and if you really mean the title of this thread, then the answer given is not correct. Just saying...

--
Paige Miller

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 1179 views
  • 0 likes
  • 4 in conversation