joskow 发表于 2009-12-17 15:09 
2# bobguy
太谢谢了。翻了手册和帮助,不知这么理解思路对吗?
data need;
array datmt (10,10) _temporary_;
do until (end);
set b end=end;
array x(10);
n+1;
do i = 1 to dim(x);
datmt (n,i)=x(i);
end;
end; /*这段是把数据集b转换成二维数组,要通过一维数组过度*/
do until (end2);
set a end=end2;
mydata=datmt (v1,v2);
output; /*用二维数组向新变量赋值。只是不明白的是为什么不能直接mydata=datmt(v1,v2),而要用循环语句?*/
end;
keep v1 v2 mydata;
run
我没有编程基础,刚刚开始学SAS编程。希望多多指教。
1) 不知这么理解思路对吗?
You should be able to design cases to check it is Right or Wrong. It should be a problem.
2)/*这段是把数据集b转换成二维数组,要通过一维数组过度*/
Think about that a SAS table is two dimentional. The first set loop just dumps the table into a 2-dimentional temporary array so that it could be referred anytime in PGM.
The following programs are equivalent
*1);
data b2;
set b;
run;
*2);
data b3;
do until(end);
set b end=end;
output;
end;
run;
Type 1) is usually you see in SAS book. Actually SAS do a lot of thing in a set statement. For example, SAS internal loop, where it puts a output statement implicitly, etc. The most important thing is SAS accesses its data set sequencially(without point option in set).
Type 2) just writes out more explicitly.There are certain avantages. For example, in this example, load data into a temporary array for look-up is much simpler that conventional ways.
I see a quite few of OLD programmers like that way because it is more like a COBOL style. And some people believe it is faster/more efficient than type 1.
3) /*用二维数组向新变量赋值。只是不明白的是为什么不能直接mydata=datmt(v1,v2),而要用循环语句?*/
I think the answer is in 2) if you understand type 2)
Beyond SAS manuals, Rick Aster wrote a SAS/BASE book "Professional SAS Programming Secrets" many years ago based on version SAS6.6, this is the only book I would recommend. Unfortunately it is quite old. He may update it ...
enjoy!
HTH.