BookmarkSubscribeRSS Feed
RandyStan
Fluorite | Level 6
I wantto round 6274.5679 to the nearest integer to get 6275

Here is what I wrote data want ; set have ; format newvar 6. ; newvar = Round(oldvar,1); run; the error i get is Variable is oldvar uninitialized.
What mistake am I making.

Randy
3 REPLIES 3
Astounding
PROC Star

Evidently, "oldvar" is the incorrect spelling.  Run a PROC CONTENTS on  your incoming data set to find the correct spelling of the variable names.

PeterClemmensen
Tourmaline | Level 20

If you want the integer portion of a variable, the INT function is what you are looking for

 

data have;
   value = 6274.5679;
   round_value = round(value);
   int_value = int(value);

   put round_value;
   put int_value;
run;
rogerjdeangelis
Barite | Level 11
 data _null_;

  x=6274.4999;
  put x hex16.;

  /* here is the problem non-terminating mantissa
     cannot represent the number exactly - you have lost already.
     
  6274.4999
  40B8827FF9724745

  like 1/3 in decimal (never is exact)
   0.3333333333333
  */

  x=62744999;
  put x hex16.;

  /* got it exactly
  62744999
  418DEB4D38000000
  */

  x=6274.5;
  put x hex16.;

  /* got it exactly (when mantissa is a power of 2**(-n))
  6274.5
  40B8828000000000
  */

  /* possible solution;
   summing in the integer domain is exact (given no overflow);
   I don not think it has to be this complex;
  */

  input numchr $9.;
  put numchr;
  numchr=compress(numchr,'.');
  exact_integer=input(numchr,9.);
  put exact_integer hex16.;
  * in microcode this should be a bit shifting operation and should be exact?;
  res=round(exact_integer,10000);
  res=res/10000;
  put res 9.4;

cards4;
6274.4999
6274.5000
6274.5001
;;;;
run;quit;



sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1528 views
  • 1 like
  • 4 in conversation