全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3313 3
2007-05-16

有哪位大侠能详细介绍一下利用go to语句进行条件“转移”的用法!

谢谢!

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2007-5-17 08:31:00

The GO TO statement and the LINK statement are similar. However, a GO TO statement is often used without a RETURN statement, whereas a LINK statement is usually used with an explicit RETURN statement. The action of a subsequent RETURN statement differs between the GO TO and LINK statements. A RETURN statement after a LINK statement returns execution to the statement that follows the LINK statement. A RETURN after a GO TO statement returns execution to the beginning of the DATA step (unless a LINK statement precedes the GO TO statement, in which case execution continues with the first statement after the LINK statement).

GO TO statements can often be replaced by DO-END and IF-THEN/ELSE programming logic.

Example:Use the GO TO statement as shown here.

  • In this example, if the condition is true, the GO TO statement instructs SAS to jump to a label called ADD and to continue execution from there. If the condition is false, SAS executes the PUT statement and the statement that is associated with the GO TO label:

· data info;

· input x;

· if 1<=x<=5 then go to add;

· put x=;

· add: sumx+x;

· datalines;

· 7

· 6

· 323

;

Because every DATA step contains an implied RETURN at the end of the step, program execution returns to the top of the step after the sum statement is executed. Therefore, an explicit RETURN statement at the bottom of the DATA step is not necessary.

  • If you do not want the sum statement to execute for observations that do not meet the condition, rewrite the code and include an explicit return statement.

· data info;

· input x;

· if 1<=x<=5 then go to add;

· put x=;

· return;

· /* SUM statement not executed */

· /* if x<1 or x>5 */

· add: sumx+x;

· datalines;

· 7

· 6

· 323

;

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2007-5-17 08:32:00
Did I answer ur question?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2007-5-17 09:22:00

thanks for your answer first!

不知道在我下面的这种情况能否用的上(迭代,我的上一个帖子问的问题);

参数估计过程中的迭代:我给参数(有多个参数)定个初始值,然后根据复杂的过程得到第一个迭代值,这过程需要一个data步1。那么如果这这迭代值与初始值之差大于某个数(这里面又需要一个data步2),用这租迭代值替换初始值,回到data步1,循环,直到他们之差小于某个数,为止。

这种情况下,我想用go to语句跳出data步2,回到data步1。不知可行?或者有其他解决办法没有?

thanks again!

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群