楼主: cfa2012
8663 4

SAS中if和end怎么匹配? [推广有奖]

  • 3关注
  • 2粉丝

已卖:45份资源

大专生

23%

还不是VIP/贵宾

-

威望
0
论坛币
139 个
通用积分
0.6000
学术水平
2 点
热心指数
2 点
信用等级
2 点
经验
750 点
帖子
31
精华
0
在线时间
35 小时
注册时间
2010-3-22
最后登录
2017-12-18

楼主
cfa2012 发表于 2013-12-3 17:42:56 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
一下是我编的一个程序:
data vitals;
input ID : #3.
Age
Pulse
SBP
DBP;
label SBP = "Systolic Blood Pressure"
DBP = "Diastolic Blood Pressure";
datalines;
001 23 68 120 80
002 55 72 188 96
003 78 82 200 100
004 18 58 110 70
005 43 52 120 82
006 37 74 150 98
007 . 82 140 100
;
if missing(age) then delete;
if age lt 50 then do;
  if pulse lt 70 then pulsegroup='Low';
   else  pulsegroup='High';
  if sbp lt 130 then sbpgroup='Low';
  else sbpgroup='High';
end;
else if age ge 50 then do;
  if pulse lt 74 then pulsegroup='Low';
   else  pulsegroup='High';
  if sbp lt 140 then sbpgroup='Low';
  else  ssbpgroup='High';
end;
run;
proc print data=vitals;
run;
运行结果显示一堆这样的错误:319  end;
     ---
     180

ERROR 180-322: 语句无效或未按正确顺序使用。
是不是if和end的使用不当,正确的用法是什么呢?望路过的大神指点迷津,谢谢啦!


二维码

扫码加我 拉你入群

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

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

关键词:End Pressure missing delete Group 程序

沙发
henryyhl 发表于 2013-12-3 20:13:16
建议看看if 语句的介绍。syntax :if 条件1 then 语句1;else if 条件2 then 语句2;最后的else 语句3;
end和do应该 是一一对应的。
It's not going to be easy, but it is going to be worth it.

藤椅
cfa2012 发表于 2013-12-3 20:18:01
henryyhl 发表于 2013-12-3 20:13
建议看看if 语句的介绍。syntax :if 条件1 then 语句1;else if 条件2 then 语句2;最后的else 语句3;
e ...
我那上面写的do 和end是匹配的吧!

板凳
henryyhl 发表于 2013-12-3 20:56:31
cfa2012 发表于 2013-12-3 20:18
我那上面写的do 和end是匹配的吧!
不好意思刚才看错了。datalines语句必须是data步中的最后一个语句,并把#改成$就应该行了。
  if sbp lt 140 then sbpgroup='Low';
  else  ssbpgroup='High';
end;
这里的  else  ssbpgroup='High';是不是要改成  else  sbpgroup='High';

data vitals;
input ID : $3.
Age
Pulse
SBP
DBP;
label SBP = "Systolic Blood Pressure"
DBP = "Diastolic Blood Pressure";
if missing(age) then delete;
if age lt 50 then do;
  if pulse lt 70 then pulsegroup='Low';
   else  pulsegroup='High';
  if sbp lt 130 then sbpgroup='Low';
  else sbpgroup='High';
end;
else if age ge 50 then do;
  if pulse lt 74 then pulsegroup='Low';
   else  pulsegroup='High';
  if sbp lt 140 then sbpgroup='Low';
  else  sbpgroup='High';
end;
datalines;
001 23 68 120 80
002 55 72 188 96
003 78 82 200 100
004 18 58 110 70
005 43 52 120 82
006 37 74 150 98
007 . 82 140 100
;
run;
It's not going to be easy, but it is going to be worth it.

报纸
cfa2012 发表于 2013-12-3 22:10:07
henryyhl 发表于 2013-12-3 20:56
不好意思刚才看错了。datalines语句必须是data步中的最后一个语句,并把#改成$就应该行了。
  if sbp lt ...
嗯,解决了,太感谢啦!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 02:28