SAS,例如,在运行/修复结果后如何停止DO循环
我目前正在尝试使用宏语言在EG中循环融合功能。我遇到的问题是循环填充了所有空列,而不仅仅是第一个空单元格。我尝试过一种逻辑形式来停止循环,但并未成功,并且通过比较相邻的列是否相同然后删除后,也尝试过解决结果。我希望循环仅填充第一个空单元格,因为之后我需要使用第二个变量运行第二个煤层循环。附件的图像显示了我得到的结果以及我的目标。
我当前的工作代码如下:
%macro coal;
data want;
set have;
%do i = 1 %to 5;
coal&i = coalescec(&column&i, var1);
%end;
run;
%mend;
.sstatic.net/sfdsa.png" alt="output wanted">
I am currently trying to loop a coalesce function in EG using macro language. The issue I'm having is the loop is populating all empty columns, rather than just the first empty cell. I have tried a form of if logic to stop the loop but not successfully and also tried and failed to fix the results after by comparing if the adjacent columns are the same and then deleting. I would like the loop to only populate the first empty cell as I need to run a 2nd coalesce loop with a 2nd variable afterwards. The attached image shows what results I am getting and what I am aiming for.
My current working code is as follows:
%macro coal;
data want;
set have;
%do i = 1 %to 5;
coal&i = coalescec(&column&i, var1);
%end;
run;
%mend;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个数组循环,找到第一个空列,退出循环,并用var1:填充该列:
An array loop, to find the first empty column, exit the loop, and populate that column with var1 :
您可以在数据步骤中完全执行此操作。如果要不断更新数据集并将其一个一个一个填充值填充,则可以使用数组。
示例数据:
代码:
第一步:
第二步:
请注意,如果您再次运行此操作,它将从
column3
将值拉入column5
。You can do this entirely within a data step. If you want to constantly update the dataset and have it fill in values one by one, you can use arrays.
Example data:
Code:
First step:
Second step:
Note that if you run this again it will pull the value from
column3
intocolumn5
.