Tom:
Thanks.
My SAS coding experience has not understood the line below yet[ _initial_&var is not called elsewhere?! ].
if first.&byvar. then _initial_&var=&var;
Ye, double transpose. It is null and tedious. But right in math. I would note care much.
In logic, the issue raises from ByVar. Transpose detours and skips this issue.
data _temp;
do grp=1 to 4;
do i=1 to 100;
x=sin(i/10.0)+grp; output;
end;
end;
run;quit;
proc sort data=_temp; by i;
run;quit;
proc transpose data=_temp out=_temp_t(drop=_name_) prefix=x_;
by i;
var x;
id grp;
run;quit;
%ema(_temp_t, x_1,0.1, 1);
%ema(_temp_t, x_2,0.2, 2);
%ema(_temp_t, x_3,0.3, 3);
%ema(_temp_t, x_4,0.4, 4);
data _temp_t; set _temp_t(rename=(x_1_ema_1=x_ema_1 x_2_ema_2=x_ema_2 x_3_ema_3=x_ema_3 x_4_ema_4=x_ema_4));
run;quit;
proc transpose data=_temp_t out=_temp_t_r;
by i;
var x_ema_:;
run;
data _temp_t_r; set _temp_t_r;
_grp_=input(substr(_name_,7,1),2.);
run;quit;
proc sort data= _temp_t_r;
by _grp_ i;
run;quit;
data _temp_t_r(rename=(col1=x_ema)); set _temp_t_r(drop=_name_);
run;quit;
proc sql;
create table _temp_t_r as
select a.*,
b.x
from _temp_t_r as a
left join _temp as b
on a.i=b.i and a._grp_=b.grp
order by a._grp_, a.i;
quit;
/*just take the reverse transpose*/
title "ema_x outcome";
ods layout gridded columns=2 rows=2 advance=table;
ods graphics /width=480px height=300px;
proc sgplot data=_temp_t_r;
by _grp_;
series x=i y=x/ lineattrs=( color=blue thickness=2 pattern=solid);
series x=i y=x_ema/ y2axis lineattrs=( color=red thickness=2 pattern=solid);
run;quit;
ods layout end;
... View more