【发布时间】:2021-09-21 10:50:08
【问题描述】:
问题很简单,希望也有答案。
有没有办法(调用执行、宏、symput 等)重写以下代码以使其更强大,以一种好的方式使用 SAS?
data get;
set have;
by pid year;
if first.year then do;
if year = 2017 then f2017 = 1;
else if year = 2018 then f2018 = 1;
else if year = 2019 then f2019 = 1;
end;
run;
这是一个尝试,但它不起作用:
data _null_;
set have end=last;
if _n_ = 1 then call execute('data get;set have;by pid year; ');
call execute(cats('if first.year then f',year,'=1;'));
if last then call execute('run;');
run;
【问题讨论】:
-
为什么会有 BY 语句和 FIRST.YEAR?请显示一些示例输入和输出数据集,以显示您实际尝试进行的转换。您确定不想使用 PROC TRANSPOSE?