automation - 用于有条件地创建 SAS 数据子类别的 SAS do-loop 问题
问题描述
data period;
set output.Sample_Y_n_deln;
if delnum >= 181 and delnum <= 184;
run;
data period2;
set output.Sample_Y_n_deln;
if delnum >= 185 and delnum <= 188;
run;
data period3;
set output.Sample_Y_n_deln;
if delnum >= 189 and delnum <= 192;
run;
有没有办法使用某种循环来自动化这个?本练习的重点是根据 delnum 获取我的数据集的季度时间片,delnum 是该数据集特定的数字格式的日期。
我听说过乍一看似乎适用的 proc 时间序列,但我对此知之甚少。
解决方案
听起来您要多次复制数据。最好只添加列以便能够快速过滤到您想要的集合。
如果期间重叠,则为每个期间添加单独的列。
data periods;
set output.Sample_Y_n_deln;
period1 = (181 <= delnum 184);
period2 = (185 <= delnum 188);
period3 = (189 <= delnum 182);
run;
您可以在分析步骤中使用 WHERE 子句中的新变量。
proc means data=periods ;
where period1 ;
...
如果期间不重叠,那么您可以只使用一个带有 PERIOD 标识符的变量。
data periods;
set output.Sample_Y_n_deln;
if (181 <= delnum 184) then period=1;
else if (185 <= delnum 188) then period=2;
else if (189 <= delnum 182) then period=3;
run;