Desktop productivity for business analysts and programmers

Strip from decimal to right from a numeric field

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

Strip from decimal to right from a numeric field

[ Edited ]

In need to round down to the nearest whole number or simply strip everything to the right of the decimal in a numeric field.  Example:

have need
1.2 1
0.1 0
10 10

Accepted Solutions
Solution
‎12-15-2015 04:48 PM
Super Contributor
Posts: 490

Re: Strip from decimal to right from a numeric field

[ Edited ]

Use the FLOOR function to round down to the next integer.

 

data a;
  input have;
  need=floor(have);
datalines;
1.2
0.1
10 123.456 34 5.1111 7.68 10.98 -3.1 -19.0 -4.8 ; proc print; run;

 

View solution in original post


All Replies
Solution
‎12-15-2015 04:48 PM
Super Contributor
Posts: 490

Re: Strip from decimal to right from a numeric field

[ Edited ]

Use the FLOOR function to round down to the next integer.

 

data a;
  input have;
  need=floor(have);
datalines;
1.2
0.1
10 123.456 34 5.1111 7.68 10.98 -3.1 -19.0 -4.8 ; proc print; run;

 

Frequent Contributor
Posts: 91

Re: Strip from decimal to right from a numeric field

Remember that the floor function gives you the next lower number, so 3.1 yields 3 and -3.1 yields -4.  The int function will give you 3 and -3 respectively.  So, choose the one that meets your specific needs.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 901 views
  • 6 likes
  • 3 in conversation