SAS中文论坛
标题:
Data步能不能嵌套?不能的话怎么处理多表数据?
[打印本页]
作者:
shiyiming
时间:
2005-8-15 12:27
标题:
Data步能不能嵌套?不能的话怎么处理多表数据?
Data步是隐含循环的
那我能不能在Data步中嵌套一个Data步
对每条table1的记录都遍历table2的所有记录
SAS里难道不能作多表的操作吗?
[code:053bf]
Data temp1;
set Table1;
Data temp2;
set Table2;
run;
run;
[/code:053bf]
就是相当于
[code:053bf]
for(int i=0,i<table1.nobs,i++){
table1.(i);//代表table1中的一条记录
for(int j>0,j<table2.nobs,j++){
table2.(j);//代表table2中的一条记录
}
}
[/code:053bf]
作者:
shiyiming
时间:
2005-8-16 09:27
标题:
to scorwill
虽然data step内不能套data step,但是你完全可以运用以下常用数据集操作的函数完成你的需求:
OPEN
FETCH
FETCHOBS
GETVARC
GETVARN
VARNAME
VARNUM
CLOSE
参见样例程序:
[code:404a3]%macro test;
%let dsid=%sysfunc(open(sashelp.class, i));
%do i=1 %to 19;
%let rc = %sysfunc(fetchobs(&dsid, &i));
%let name=%sysfunc(getvarc(&dsid, %sysfunc(varnum (&dsid, NAME))));
%put &name;
%end;
%let rc=%sysfunc(close(&dsid));
%mend;
%test;[/code:404a3]
[code:404a3]data vars;
length name $ 8 type $ 1 format informat $ 10 label $ 40;
drop dsid i num rc;
dsid=open("sashelp.class","i");
num=attrn(dsid,"nvars");
do i=1 to num;
name=varname(dsid,i);
type=vartype(dsid,i);
format=varfmt(dsid,i);
informat=varinfmt(dsid,i);
label=varlabel(dsid,i);
length=varlen(dsid,i);
position=varnum(dsid,name);
output;
end;
rc=close(dsid);
run;[/code:404a3]
你可以仔细琢磨一下,一定能有所领悟的。 <!-- s:idea: --><img src="{SMILIES_PATH}/icon_idea.gif" alt=":idea:" title="Idea" /><!-- s:idea: -->
欢迎光临 SAS中文论坛 (http://mysas.net/forum/)
Powered by Discuz! X3.2