SAS Do循环正在处理中忽略行
我有以下代码。我试图测试一个段落(descr)的关键字列表(关键字)。当我执行这段代码时,日志读取数组的所有变量,但只测试do循环中20000行中的2行(do I=1到100,等等)。对如何解决这个问题有什么建议吗SAS Do循环正在处理中忽略行,sas,do-loops,datastep,Sas,Do Loops,Datastep,我有以下代码。我试图测试一个段落(descr)的关键字列表(关键字)。当我执行这段代码时,日志读取数组的所有变量,但只测试do循环中20000行中的2行(do I=1到100,等等)。对如何解决这个问题有什么建议吗 data JE.KeywordMatchTemp1; set JE.JEMasterTemp end=eof; if _n_ = 1 then do i = 1 by 1 until (eof); set JE.KeyWords; array keywords
data JE.KeywordMatchTemp1;
set JE.JEMasterTemp end=eof;
if _n_ = 1 then do i = 1 by 1 until (eof);
set JE.KeyWords;
array keywords[100] $30 _temporary_;
keywords[i] = Key_Words;
end;
match = 0;
do i = 1 to 100;
if index(descr, keywords[i]) then match = 1;
end;
drop i;
run;
您的问题是您的
end=eof
位于错误的位置
这是一个计算每个SASHELP.CLASS
受访者年龄值“等级”的简单示例
请参见我将end=eof
放在何处。这是因为您需要使用它来控制数组填充操作。否则,所发生的是您的循环,doi=1到eof
并没有真正做到你所说的它应该做到的:它实际上并没有在eof
处终止,因为这从来都不是真的(正如第一条set
语句中定义的那样)。相反,它会终止,因为您超出了数据集的末尾,而这正是您不想要的
这就是end=eof
的作用:它阻止您在数组填充数据集完成时尝试提取行,从而终止整个数据步骤。每当您看到一个数据步骤在两次迭代之后终止时,您都可以确信这就是问题的可能所在——这是一个非常常见的问题
data class_ranks;
set sashelp.class; *This dataset you are okay iterating over until the end of the dataset and then quitting the data step, like a normal data step.;
array ages[19] _temporary_;
if _n_=1 then do;
do _i = 1 by 1 until (eof); *iterate until the end of the *second* set statement;
set sashelp.class end=eof; *see here? This eof is telling this loop when to stop. It is okay that it is not created until after the loop is.;
ages[_i] = age;
end;
call sortn(of ages[*]); *ordering the ages loaded by number so they are in proper order for doing the trivial rank task;
end;
age_rank = whichn(age,of ages[*]); *determine where in the list the age falls. For a real version of this task you would have to check whether this ever happens, and if not you would have to have logic to find the nearest point or whatnot.;
run;
非常感谢。如果可以的话,还有一件事。当条件满足时,代码第二部分中的DO循环似乎没有停止。任何可能发生的原因?当
i=100
时不停止?或者在match=1时不停止?后者不会阻止它,为什么会呢?