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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 773 views
  • 1 like
  • 4 in conversation