今回はIF文の分岐で、複数の命令を実行する方法について、解説していきます。
【併せて読みたい記事】
- 【SAS】IFステートメントは処理を分岐できる。その1 | ビジネスイッチ (how-to-business.com)
- 【SAS】IFステートメントは処理を分岐できる。その2~ELSE IF、ELSE~ | ビジネスイッチ (how-to-business.com)
/* then do_1 */
data data1;
id1="1111"; id2="1111"; id3="1111";
output;
run;
data data2; set data1;
if id1 = "1111" then do;
id4 = "1111";
id5 = "1111";
end;
else if id1 = "2222" then do;
id4 = "2222";
id5 = "2222";
end;
else do;
id4 = "3333";
id5 = "3333";
end;
run;


- then do~end, else do~endを使う事で、複数の命令文を実行できる。
- 最初のifステートメントがTRUEであるため、id4 = “1111” id5=”1111″となる。
/* then do_2 */
data data1;
id1="2222"; id2="2222"; id3="2222";
output;
run;
data data2; set data1;
if id1 = "1111" then do;
id4 = "1111";
id5 = "1111";
end;
else if id1 = "2222" then do;
id4 = "2222";
id5 = "2222";
end;
else do;
id4 = "3333";
id5 = "3333";
end;
run;


- then do~end, else do~endを使う事で、複数の命令文を実行できる。
- 第2文のelse ifステートメントがTRUEであるため、id4 = “2222” id5=”2222″となる。
/* then do_3 */
data data1;
id1="3333"; id2="3333"; id3="3333";
output;
run;
data data2; set data1;
if id1 = "1111" then do;
id4 = "1111";
id5 = "1111";
end;
else if id1 = "2222" then do;
id4 = "2222";
id5 = "2222";
end;
else do;
id4 = "3333";
id5 = "3333";
end;
run;


- then do~end, else do~endを使う事で、複数の命令文を実行できる。
- 第3文のelse doステートメントがTRUEであるため、id4 = “3333” id5=”3333″となる。
/* end無し_1 */
data data1;
id1="1111"; id2="1111"; id3="1111";
output;
run;
data data2; set data1;
if id1 = "1111" then do;
id4 = "1111";
id5 = "1111";
else if id1 = "2222" then do;
id4 = "2222";
id5 = "2222";
else do;
id4 = "3333";
id5 = "3333";
run;

- then do~end, else do~endを使う事で、複数の命令文を実行できる。
- DOブロックに対して、ENDで閉じてないとエラーとなる。