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

Leave a Reply

Your email address will not be published. Required fields are marked *