s******o 发帖数: 283 | 1 Item 52
To create a dataset with unique values of a given varible using a data
step
and the FIRST. and LAST. varaibales, it is
assumed that the input dataset is:
A. sorted on that variable.
B. indexed by that variable.
C. naturally in order.
D. any of the above A, B, or C
答案为何不是D?因为这里只是要求unique value,所以在同一个组里的任意一个值都可以,所以在
这里对顺序并没有要求,所以并不要求sort or index or any order???? | s******o 发帖数: 283 | 2 自己顶一下,有没有高人可以解释一下答案为啥是A呢?thanks a lot!
都可以,所以在
【在 s******o 的大作中提到】 : Item 52 : To create a dataset with unique values of a given varible using a data : step : and the FIRST. and LAST. varaibales, it is : assumed that the input dataset is: : A. sorted on that variable. : B. indexed by that variable. : C. naturally in order. : D. any of the above A, B, or C : 答案为何不是D?因为这里只是要求unique value,所以在同一个组里的任意一个值都可以,所以在
| f**********6 发帖数: 365 | 3 first, last only work with sorted dataset.
都可以,所以在
【在 s******o 的大作中提到】 : Item 52 : To create a dataset with unique values of a given varible using a data : step : and the FIRST. and LAST. varaibales, it is : assumed that the input dataset is: : A. sorted on that variable. : B. indexed by that variable. : C. naturally in order. : D. any of the above A, B, or C : 答案为何不是D?因为这里只是要求unique value,所以在同一个组里的任意一个值都可以,所以在
| s******o 发帖数: 283 | 4 thanks for your help,
but from SAS base "reading SAS dataset----using By-group processing" it
says,
"When you use the BY statement with the SET statement,
the data sets that are listed in the SET statement must be sorted by the
values of the BY variable(s), or they must have an appropriate index."
so answer B is possible?
and from adv-prep-guide,
"The NOTSORTED option can be used with FIRST.variable and LAST.variable,
example:
data work.new;
set company.sales
by ordername notsorted;
run;
"
so answer C is possible?
so overall, the answer is D?
【在 f**********6 的大作中提到】 : first, last only work with sorted dataset. : : 都可以,所以在
| p*******i 发帖数: 1181 | 5 这个C肯定不行 我工作时候碰到过 都是Excel里排好然后导入的 还是会报错 sort以后
就没问题了 | s******o 发帖数: 283 | 6 do you mean if you use " notsorted " option in the by statement, it still
canot work?
【在 p*******i 的大作中提到】 : 这个C肯定不行 我工作时候碰到过 都是Excel里排好然后导入的 还是会报错 sort以后 : 就没问题了
| d******9 发帖数: 404 | 7 The answer should be D.
I tried with below data: natural in order.
data A;
input A B $;
cards;
1 a
5 t
5 W
7 h
9 D
;
run;
data B;
set A;
by A;
if first.A then output;
run;
SAS Output:
Obs A B
1 1 a
2 5 t
3 7 h
4 9 D | d******9 发帖数: 404 | 8 No.
Please see me below example.
【在 f**********6 的大作中提到】 : first, last only work with sorted dataset. : : 都可以,所以在
| s******o 发帖数: 283 | 9 Thanks so much for your help again, dido2009.
I know you did not sort the data set A before you use it for data B.But
does
data set A itself look like it is sorted already? because A variable in
this dataset is arranged in ascending order(1,5,7,9) already? and when
you
use it for data B, there is
set A;
By A;
with the combination of "set" and "by" statement, it require that data A
is
sorted or indexed as I referred above in SAS base"By group processing"
??
Do you know the result if the data set A has variable A in the random
order(
e.g. 1, 7,5,9) and is it possible to produce data B using "set"
statement
without "by" statement(because varialbe A is not sorted here)?
【在 d******9 的大作中提到】 : The answer should be D. : I tried with below data: natural in order. : data A; : input A B $; : cards; : 1 a : 5 t : 5 W : 7 h : 9 D
| s******o 发帖数: 283 | 10 dido2009, thanks for your help, I actually run the code below:
data C;
input A B $;
cards;
5 t
5 W
7 h
1 a
9 D
;
run;
data B;
set C;
By A notsorted;
if first.A then output;
run;
and the SAS result is
5 t
7 h
1 a
9 D
so as you said answer C is possible( when data is in natural order). then
answer is D.
【在 s******o 的大作中提到】 : Thanks so much for your help again, dido2009. : I know you did not sort the data set A before you use it for data B.But : does : data set A itself look like it is sorted already? because A variable in : this dataset is arranged in ascending order(1,5,7,9) already? and when : you : use it for data B, there is : set A; : By A; : with the combination of "set" and "by" statement, it require that data A
|
|