根据一个变量的值将 SAS 数据集拆分为多个数据集 [英] Splitting a SAS dataset into multiple datasets, according to value of one variable
本文介绍了根据一个变量的值将 SAS 数据集拆分为多个数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有更简化的方法来实现这一点?这是一个简化的例子.在实际情况下,var
有 > 10 个值,每个值都需要自己的数据集.
数据新1新2新3;设置旧;如果 var = 'new1' 然后输出 new1;否则如果 var = 'new2' 然后输出 new2;else if var = 'new3' 然后输出 new3;跑步;
解决方案
这应该可以解决.您只需要将 % 更改为 5 到 10(最大新数字).@Reeza 提出的观点很棒.我也会看看那个帖子,因为它是一个重要的建议.通常这不是处理数据的好方法,但这应该可以帮助您解决问题.
数据有;输入变量 $;数据线;新1新2新3新4新5;跑步;
<块引用>
*实际代码从这里开始;
%宏拆分;%do i=1 % 到 5;%put "new&i";进程sql;创建表 table&i as选择 *从有其中 var 包含new&i";放弃;%结尾;%修正分裂;%分裂;
Is there a more streamlined way of accomplishing this? This is a simplified example. In the real case there are > 10 values of var
, each of which need their own dataset.
data
new1
new2
new3;
set old;
if var = 'new1' then output new1;
else if var = 'new2' then output new2;
else if var = 'new3' then output new3;
run;
解决方案
This should work out. You just need to change the %to 5 to 10 (the max new number). The point made by @Reeza is great. I would also take a look at that post since it's an important suggestion. Usually this is not a good way to handle data, but this should get you around.
data have;
input var $;
datalines;
new1
new2
new3
new4
new5
;
run;
*Actual code starts here;
%macro splitting;
%do i=1 %to 5;
%put "new&i";
proc sql;
create table table&i as
select *
from have
where var contains "new&i";
quit;
%end;
%mend splitting;
%splitting;
这篇关于根据一个变量的值将 SAS 数据集拆分为多个数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文