【发布时间】:2018-07-11 07:14:15
【问题描述】:
我正在做一些小任务来提高我的编码和效率,我今天正在处理的问题来自 Euler 项目,问题 3:
“找出 600851475143 中最大的素数”
我写的代码是:
data test;
a = 600851475143;
/*The subsequent a's are the next parts of the loop I'm trying to incorporate*/
/*a = 8462696833;*/
/*a = 10086647;*/
/*a = 6857;*/
if mod(a,2) = 0 then do;
a = a / 2;
end;
else do;
do i = 3 to a until(flag);
if mod(a,i) = 0 and i < a then do;
b = i ;
a = a / b ;
flag = 1;
output;
end;
end;
end;
run;
如何使变量 a 循环并变小,然后在没有 a 时终止,即最后一次迭代不会产生数据集,因为没有分解。
我也很高兴收到有关如何使这段代码更高效的任何提示,因为我正在努力学习
【问题讨论】:
-
这类问题更适合codereview.stackexchange.com - 你试过在那里发帖吗?
-
我承认,我以前没有听说过那个地区...
标签: loops if-statement sas do-loops sas-studio