今回もDROPについて解説します。
(対比:KEEP 【SAS】KEEPはカラムの選択に使える。 | ビジネスイッチ (how-to-business.com))
過去記事ではDROPの使い方について解説しました。⇒【SAS】DROPはデータセットから変数を削除する | ビジネスイッチ (how-to-business.com)
今回はDROPで良く問われがちな間違った使用法に触れていきます。特にSAS Base Programming試験後半の四者択一問題で問われることが多いと思います。
/* drop_1 */
data data1;
Id1=1111; Id2=1111; Id3=1111; Id4=1111;
output;
Id1=2222; Id2=2222; Id3=2222; Id4=2222;
output;
Id1=3333; Id2=3333; Id3=3333; Id4=3333;
output;
run;
data data2; set data1;
drop=Id2 Id3;
run;


- drop=Id2 Id3;はエラーとなる。
/* drop_2 */
data data1;
Id1=1111; Id2=1111; Id3=1111; Id4=1111;
output;
Id1=2222; Id2=2222; Id3=2222; Id4=2222;
output;
Id1=3333; Id2=3333; Id3=3333; Id4=3333;
output;
run;
data data2; set data1;
drop=Id2,Id3;
run;


- drop=Id2,Id3;はエラーとなる。
/* drop_3 */
data data1;
Id1=1111; Id2=1111; Id3=1111; Id4=1111;
output;
Id1=2222; Id2=2222; Id3=2222; Id4=2222;
output;
Id1=3333; Id2=3333; Id3=3333; Id4=3333;
output;
run;
data data2(drop Id2 Id3); set data1;
run;


- (drop Id2 Id3)はエラーとなる。
/* drop_4 */
data data1;
Id1=1111; Id2=1111; Id3=1111; Id4=1111;
output;
Id1=2222; Id2=2222; Id3=2222; Id4=2222;
output;
Id1=3333; Id2=3333; Id3=3333; Id4=3333;
output;
run;
data data2(drop=Id2,Id3); set data1;
run;


- (drop=Id2,Id3)はエラーとなる。