szclx 发表于 2010-1-15 13:24
例如:
v1有5个数据。但事先不知道有5个,怎样才能在data步中计算出有5个样本呢?.
data a;
input v1;
cards;
1
2
3
4
5;
data b;
set a;
sum=_n_/5;
这个是个例子。
如果说不知道样本数有多少的话。有没有能自动化的在data步中算出5?
proc summary data=a;
var v1;
output out=c n=n;
是想过以上这个方法计算出n来。但是不懂得怎么用到里面去。
请教大家教教我。
Not exactly sue what you want.
If you want to know how many obs in a data set, you don't even need to open it.
SAS stores a data set into two pieces after Version 5 --- the descriptive information or head file and data.
The descriptive information can be accessed in compiling time.
Here is an example.
43
44 data t1;
45 do i= 1 to 5;
46 output;
47 end;
48 run;
NOTE: The data set WORK.T1 has 5 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
49
50 data _null_;
51 if 0 then set t1 nobs=number_of_obs_on_t1 ;
52 put number_of_obs_on_t1=;
53 run;
number_of_obs_on_t1=5
NOTE: DATA STEP stopped due to looping.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds