SAS从多个变量创建新变量

SAS从多个变量创建新变量,sas,recode,Sas,Recode,我很不好意思问这个问题,因为它看起来很简单,但我想不出来 我正在尝试基于多个if-then语句创建一个新变量。 例如: if question1=1 then newvar=1; if question2=1 then newvar=2; if question3=1 and question4=1 then newvar=3; if question5 in (1 2) then newvar=4; if question1=2 then newvar=5; 我想我可能会用每条语句

我很不好意思问这个问题,因为它看起来很简单,但我想不出来

我正在尝试基于多个if-then语句创建一个新变量。 例如:

 if question1=1 then newvar=1;
 if question2=1 then newvar=2;
 if question3=1 and question4=1 then newvar=3;
 if question5 in (1 2) then newvar=4;
 if question1=2 then newvar=5;

我想我可能会用每条语句覆盖newvar?是这样吗?

您只是缺少了
其他
语句:

if question1=1 then newvar=1; else if question2=1 then newvar=2; else if question3=1 and question4=1 then newvar=3; else if question5 in (1 2) then newvar=4; else if question1=2 then newvar=5; 如果问题1=1,则newvar=1; 其他的 如果问题2=1,则newvar=2; 其他的 如果问题3=1,问题4=1,则newvar=3; 其他的 如果(12)中的问题5,则newvar=4; 其他的 如果问题1=2,则newvar=5;