data numbers;
drop i j;
array a[5];
do j = 1 to 5;
do i = 1 to 5;
a[i] = ranuni(12345) * (i+123.234);
end;
output;
end;
run;
%macro standardize;
%let dsname = %sysfunc(dequote(&dsname));
%let colname = %sysfunc(dequote(&colname));
proc standard data = &dsname mean = &MEAN std = &STD out=_out;
var &colname;
run;
data &dsname;
set _out;
run;
%mend standardize;
proc fcmp outlib = sasuser.ds.functions;
subroutine standardize(x[*], mean, std);
outargs x;
rc = write_array('work._TMP_', x, 'x1');
dsname = 'work._TMP_';
colname = 'x1';
rc = run_macro('standardize', dsname, colname, mean, std);
array x2[1]_temporary_;
rc = read_array('work._TMP_', x2);
if dim(x2) = dim(x) then do;
do i = 1 to dim(x);
x[i] = x2[i];
end;
end;
endsub;
run;
options cmplib = (sasuser.ds);
data numbers2;
set numbers;
array a[5];
array t[5]_temporary_;
do i = 1 to 5;
t[i] = a[i];
end;
call standardize(t, 0, 1);
do i = 1 to 5;
a[i] = t[i];
end;
output;
run;
proc print data=work.numbers2;
run;
Program Description
proc fcmp outlib = sasuser.ds.functions;
subroutine standardize(x[*], mean, std);
outargs x;
rc = write_array('work._TMP_', x, 'x1');
dsname = 'work._TMP_';
colname = 'x1';
rc = run_macro('standardize', dsname, colname, mean, std);
array x2[1]_temporary_;
rc = read_array('work._TMP_', x2);
if dim(x2) = dim(x) then do;
do i = 1 to dim(x);
x[i] = x2[i];
end;
end;
endsub;
run;
options cmplib = (sasuser.ds);
data numbers2;
set numbers;
array a[5];
array t[5]_temporary_;
do i = 1 to 5;
t[i] = a[i];
end;
call standardize(t, 0, 1);
do i = 1 to 5;
a[i] = t[i];
end;
output;
run;