If statement If-then-else匹配问题

If statement If-then-else匹配问题,if-statement,sas,If Statement,Sas,运行此代码时出现错误 不匹配if-then子句 如果x=1,则执行; 如果diff>12和(8我复制了您的代码并运行以下程序: data test; x = 1; diff = 14; p=14; if x=1 then do; if diff>12 and (8<=p<=12 or 3<=p<5) then g=1; else if (1<=p<=2) then g=2; else g=3; end; run; 数据测试; x=1

运行此代码时出现错误

不匹配if-then子句

如果x=1,则执行;

如果diff>12和(8我复制了您的代码并运行以下程序:

data test;
x = 1;
diff = 14;
p=14;

if x=1 then do;
   if diff>12 and (8<=p<=12 or 3<=p<5) then g=1;
   else if (1<=p<=2) then g=2;
   else g=3;
end;
run;
数据测试;
x=1;
差异=14;
p=14;
如果x=1,则执行;

如果差异>12且(8@dwn这相当于c中的
if(){}
do
开始一个以
end
结尾的块(否则
if
只会影响到
)。@user1009587上面的语句没有根本性的错误,所以您肯定还有其他问题(例如,在此之前可能缺少一个分号)。@user1009587啊,好的,谢谢你提供的信息。问题解决了。事实上,代码中有一些注释掉的部分末尾有分号。删除它们后效果很好。Thnx all。。
data test;
x = 1;
diff = 14;
p=14;

if x=1 then do;
   if diff>12 and (8<=p<=12 or 3<=p<5) then g=1;
   else if (1<=p<=2) then g=2;
   else g=3;
end;
run;