2014-02-28 57 views
0

我想創建一個快速代碼寫入的循環。 我希望x1- x30的每一個可能性都相等:x平方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; 

回答

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; 
+0

此代碼給1個觀察我需要2000 – dmitriy

+0

它給我的只是其中的第一步循環(i = -10)。 – dmitriy

+0

有一個錯字,並意識到你應該將第二個循環的循環計數器切換到別的東西 - 修正 – Joe