SAS IF, IF-THEN and IF-THEN-ELSE Statements
Conditional statements (if-then statements, if-then-else statements) are often used to assign values to variables. Example:
data new;
input prefix age sex $;
if prefix=821 then city='auburn';
if age <30 then young=1;
else young=0; 公卫论坛
if age<30 and sex='f' then yw=1;
if age>80 or prefix='749' then nogood=1;
.....
The logical connectives AND and OR are used to create compound tests, as illustrated above.
A counterless do-loop can be used to have more complicated processing after an if-branch. Example:
if age<30 then do;
if income<20000 then cat=1;
if income>20000 and income <30000 then cat=2;
end;
....
The return statement can be used to branch to the bottom of the data step program.
Do-loops and if-then statements can be nested. 公卫家园
data new;
input prefix age sex $;
if prefix=821 then city='auburn';
if age <30 then young=1;
else young=0; 公卫论坛
if age<30 and sex='f' then yw=1;
if age>80 or prefix='749' then nogood=1;
.....
The logical connectives AND and OR are used to create compound tests, as illustrated above.
A counterless do-loop can be used to have more complicated processing after an if-branch. Example:
公卫考场
if age<30 then do;
if income<20000 then cat=1;
if income>20000 and income <30000 then cat=2;
end;
....
The return statement can be used to branch to the bottom of the data step program.
Do-loops and if-then statements can be nested. 公卫家园
附件列表
词条内容仅供参考,如果您需要解决具体问题
(尤其在法律、医学等领域),建议您咨询相关领域专业人士。
如果您认为本词条还有待完善,请 编辑