Sample 25236: Find the least common multiple of two numbers
Determine the least common multiple (LCM) of X and Y.
The LCM of two numbers is the smallest number (not
zero) that is a multiple of both.
Note:
The least common denominator for two fractions is the least common multiple of their denominators.
Given
x*y=GCD(x,y)*LCM(x,y)
(GCD - greatest common divisor)
(LCM - least common multiple)
the formula can be re-written as
LCM(x,y)=x*y/GCD(x,y)
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
data a (drop=T:);
input X Y;
T1=X;
T2=Y;
do while(T2 gt 0);
T3=mod(T1,T2);
T1=T2;
T2=T3;
end;
GCD_XY=T1;
LCM_XY=X*Y/GCD_XY;
datalines;
2 3
3 4
6 144
88 92
;
proc print;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Obs X Y GCD_XY LCM_XY
1 2 3 1 6
2 3 4 1 12
3 6 144 6 144
4 88 92 4 2024
Determine the least common multiple (LCM) of X and Y.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions ==> Mathematical
|
| Date Modified: | 2005-12-23 03:02:57 |
| Date Created: | 2005-02-17 14:55:52 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |