The following SAS program is submitted:
data WORK.AUTHORS;
array Favorites{3} $ 8 (‘Shakespeare’,’Hemingway’,’McCaffrey’);
run;
What is the value of the second variable in the dataset WORK.AUTHORS?
A. Hemingway
B. Hemingwa
C. ‘ ‘ (a missing value)
D. The program contains errors. No variables are created.
Answer: B
注解:ARRAY statement中,Favorites为数组名字,{3}表示数组中有3个元素,$表示数组中的元素为字符型,8表示数组内的值最长为8个字节,(‘Shakespeare’,’Hemingway’,’McCaffrey’)设定数组元素的初始值。第二个数组元素,即 Favorites{2},得到的初始值为’Hemingway’,但由于定义了最长8个字符,所以其值为Hemingwa。