- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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