SAS Do Loop 在处理过程中忽略行
SAS Do Loop is Omitting Rows in Processing
我有以下代码。我正在尝试针对关键字列表 (key_words) 测试段落 (descr)。当我执行这段代码时,日志读取数组的所有变量,但只会测试 do 循环中 20,000 行中的 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[100] _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
受访者年龄值 'rank' 的简单示例。
看看我把 end=eof
放在哪里了。那是因为你需要用它来控制数组的填充操作。否则,会发生什么是你的循环 do i = 1 to eof;
并没有真正按照你说的去做:它实际上并没有在 eof
处终止,因为那永远不是真的(因为它在 第一个 set
语句)。相反,它会终止,因为您超出了数据集的末尾,这正是您不想要的。
这就是 end=eof
正在做的事情:它阻止您在数组填充数据集完成时尝试拉一行,这会终止整个数据步骤。每当您看到一个数据步骤在恰好 2 次迭代后终止时,您可以确信这就是问题所在 - 这是一个非常常见的问题。
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;
我有以下代码。我正在尝试针对关键字列表 (key_words) 测试段落 (descr)。当我执行这段代码时,日志读取数组的所有变量,但只会测试 do 循环中 20,000 行中的 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[100] _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
受访者年龄值 'rank' 的简单示例。
看看我把 end=eof
放在哪里了。那是因为你需要用它来控制数组的填充操作。否则,会发生什么是你的循环 do i = 1 to eof;
并没有真正按照你说的去做:它实际上并没有在 eof
处终止,因为那永远不是真的(因为它在 第一个 set
语句)。相反,它会终止,因为您超出了数据集的末尾,这正是您不想要的。
这就是 end=eof
正在做的事情:它阻止您在数组填充数据集完成时尝试拉一行,这会终止整个数据步骤。每当您看到一个数据步骤在恰好 2 次迭代后终止时,您可以确信这就是问题所在 - 这是一个非常常见的问题。
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;