开发者

SAS I want to use an iteration variable to declare variables on a data set [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜