Study SAS

統計解析ソフトウェアSASについて学習したことのまとめやSAS認定試験対策など

SAS Base Programmer 練習問題19

以下のような内容のデータセットQTR1_REVENUEがある。

destination revenue
YYZ 53634
FRA 62129
FRA 75962
RDU 76254
YYZ 82174

次のSASプログラムをコミットする。

proc sort data = qtr1_revenue;
    by destination descending revenue;
run;

出力データセットの最初のオブザーベーションはどれか

A.

destination revenue
YYZ 82174

B.

destination revenue
YYZ 53634

C.

destination revenue
FRA 62129

D.

destination revenue
FRA 75962

出典はこちら


答え: D (要反転)

変数destinationについて辞書の順番で並び替え、かつ同じdestinationのオブザーベーションについてrevenueの大きい順で並び替える。

data qtr1_revenue;
    destination = 'YYZ'; revenue = 53634; output;
    destination = 'FRA'; revenue = 62129; output;
    destination = 'FRA'; revenue = 75962; output;
    destination = 'RDU'; revenue = 76254; output;
    destination = 'YYZ'; revenue = 82174; output;
run;

proc sort data = qtr1_revenue;
    by destination descending revenue;
run;

このコードを実行すると以下の並び替えの結果が得られる。

destination revenue
FRA 75962
FRA 62129
RDU 76254
YYZ 82174
YYZ 53634