用循环编写的快捷方式代码

时间:2014-02-28 13:47:12

标签: sas

我正在尝试创建一个可以快捷编写代码的循环。 我希望x1- x30中每个可验证的都是相等的:x square i,当i是x1的索引(即1)时。

例如x7将是x7 = x ** 7;

我写了一段代码,但它不起作用。而且我不知道如何解决他。我很乐意帮助你们。

DATA maarah (drop = i e);
e = constant("e");
do i = -10 to 10 by 0.01;
x=i;
y=e**x;
output;
end;
length x1-x30 $2001;
do i =1 to 30 by 1;
x i=x**i;
output;
end;
run;

1 个答案:

答案 0 :(得分:2)

你很亲密。你需要声明一个数组。你没有解释上半部分是什么(e ** i部分),所以不清楚你想要的是什么 - 你想要几千行的e,然后一些行x1-x30?为什么每次都在第二次循环中输出?要回答核心问题,请点击此处:

DATA maarah (drop = i e);
e = constant("e");
do i = -10 to 10 by 0.01;
x=i;
y=e**x;
output;
end;

*length x1-x30 $2001; *what is this?  Why do you want it 2001 characters, instead of numeric?;
array xs x1-x30; *you would need a $ after this if you truly wanted character;
do i =1 to 30 by 1;
 xs[i]=x**i;
*output; *You probably do not want this.  Output is probably outside of the loop.;
end;
run;

我猜你真正想要的是这个:

 DATA maarah (drop = i e);
e = constant("e");
do i = -10 to 10 by 0.01;
 x=i;
 y=e**x;
 *length x1-x30 $2001; *what is this?  Why do you want it 2001 characters, instead of numeric?;
 array xs x1-x30; *you would need a $ after this if you truly wanted character;
 do j =1 to 30;
   xs[j]=x**j;
 end; *the x1-x30 loop;
 output;  
end;  *the outer loop;
run;