SAS Base (27)

Given the SAS data set WORK.TEMPS:

Day Month Temp
1 May 75
15 May 70
15 June 80
3 June 76
2 July 85
14 July 89

The following program is submitted:

proc sort data=WORK.TEMPS;
by descending Month Day;
run;

proc print data=WORK.TEMPS;
run;

Which output is correct?

A.

Obs Day Month Temp
1 2 July 85
2 14 July 89
3 3 June 76
4 15 June 80
5 1 May 75
6 15 May 70

B.

Obs Day Month Temp
1 1 May 75
2 2 July 85
3 3 June 76
4 14 July 89
5 15 May 70
6 15 June 80

C.

Obs Day Month Temp
1 1 May 75
2 15 May 70
3 3 June 76
4 15 June 80
5 2 July 85
6 14 July 89

D.

Obs Day Month Temp
1 15 May 70
2 1 May 75
3 15 June 80
4 3 June 76
5 14 July 89
6 2 July 85
Check Answer
Answer: C

注解:DESCENDING只作用于紧跟着它的那一个变量,所以输出的结果应当先按Month降序排列,相同的Month再按Day升序排列。Month是字符型,所以按照英文字母的顺序倒序排列。注意,SAS并不知道May是5月,June是6月,SAS只知道May的第一个字母是M,而June的第一个字母是J。字符型变量的排序在采用不同编码表的操作系统中略有不同。

采用ASCII编码的系统,例如Windows,Linux和MAC OS中,各字符从小到大的排列顺序为:
空格 ! ” # $ % & ‘ ( ) * + , – . /0 1 2 3 4 5 6 7 8 9 : ; < = > ? @
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z[ ] ˆ_
a b c d e f g h i j k l m n o p q r s t u v w x y z { } ~

采用EBCDIC编码的系统,例如z/OS,各字符从小到大的排列顺序为:
空格 . < ( + | & ! $ * ) ; ¬ – / , % _ > ?: # @ ‘ = “
a b c d e f g h i j k l m n o p q r ~ s t u v w x y z
{ A B C D E F G H I } J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9

SAS Base (26)

Which step sorts the observations of a permanent SAS data set by two variables and stores the sorted observations in a temporary SAS data set?

A.
proc sort out=EMPLOYEES data=EMPSORT;
by Lname and Fname;
run;

B.
proc sort data=SASUSER.EMPLOYEES out=EMPSORT;
by Lname Fname;
run;

C.
proc sort out=SASUSER.EMPLOYEES data=WORK.EMPSORT;
by Lname Fname;
run;

D.
proc sort data=SASUSER.EMPLOYEES out=SASUSER.EMPSORT;
by Lname and Fname;
run;

Check Answer
Answer: B

注解:DATA指定需要被排序的data set,OUT指定存放排序后数据的data set,如果省略OUT,SAS则会用排序后的数据替换原始数据。BY statement后直接列出需要排序的变量名,并以空格隔开。WORK library中的dataset都为临时data set,即关闭SAS后这些数据都将被移除,以WORK.dataset表示,其中WORK可以省略,例如:WORK.EMPSORT或EMPSORT。其他library中的都为永久data set,以libref.dataset表示,例如:SASUSER.EMPLOYEES。