SAS I want to use an iteration variable to declare variables on a data set [closed]
I want to use i
to be part of a defining variable like var_1,var_2,.....va开发者_JAVA技巧r_16
also if i have Rate1,Rate2,....Rate15
How can i do that to:
Have this var_1=Rate1(substitue by its value 1)
Data s;
format Sr var_1-var_16 ;
Rate1=1;
Rate2=2;
do i=1 to 15 by 1;
var_i=Ratei;
end;
run;
This is my best guess as to what you're asking: You have 16 variables, var_1, ..., var_16
and you want to assign each of their values to another set of variables Rate1, ..., Rate16
.
This will work:
data s;
array var{*} var_1-var_16;
array Rate{16};
do i=1 to 15;
Rate{i} = var{i};
end;
drop i;
run;
Here's a method that uses macros. Personally I find parsing the %'s easier than working with arrays, but that's just me.
%macro foo;
data s;
%do i = 1 %to 16;
var_&i = rate&i;
%end;
run;
%mend;
%foo
精彩评论