如何将SAS代码转换为SAS宏?

如何将SAS代码转换为SAS宏?,sas,sas-macro,Sas,Sas Macro,当SC变为1到6时,您会将这些SAS代码转换为短宏吗 if SC=1 and u_rep =1 and ((co1*(Daily**2))+(co_dem_1*daily)+(int_1))>99.7 then exp_val =1; Else if SC=1 and u_rep =1 and ((co1*(Daily**2))+(co_dem_1*daily)+(int_1))<99.7 then exp_val=(( co_dem_1*((co1*(Daily**2))+(c

当SC变为1到6时,您会将这些SAS代码转换为短宏吗

if SC=1 and u_rep =1 and ((co1*(Daily**2))+(co_dem_1*daily)+(int_1))>99.7 then
exp_val =1;

Else if SC=1 and u_rep =1 and  ((co1*(Daily**2))+(co_dem_1*daily)+(int_1))<99.7
then
exp_val=(( co_dem_1*((co1*(Daily**2))+(co_dem_1*daily)+(int_1))/100
;



if SC=2 and u_rep =1 and ((co2*(Daily**2))+(co_dem_2*daily)+(int_2))>99.7 then
exp_val =1;

Else if SC=2 and u_rep =1 and  ((co2*(Daily**2))+(co_dem_2*daily)+(int_2))<99.7
then
exp_val=(( co_dem_2 *((co2*(Daily**2))+(co_dem_2*daily)+(int_1))/100
;


if SC=3 and u_rep =1 and ((co3*(Daily**2))+(co_dem_3*daily)+(int_3))>99.7 then
exp_val =1;

Else if SC=2 and u_rep =1 and  ((co3*(Daily**2))+(co_dem_3*daily)+(int_3))<99.7
then
exp_val=(( co_dem_3*((co3*(Daily**2))+(co_dem_3*daily)+(int_3))/100
;

如果SC=1且u_rep=1且((co1*(Daily**2))+(co_dem_1*Daily)+(int_1))>99.7,则
exp_val=1;
否则,如果SC=1,u_rep=1和((co1*(Daily**2))+(co_dem_1*Daily)+(int_1))99.7,则
exp_val=1;
否则,如果SC=2,u_rep=1和((co2*(每日**2))+(co_dem_2*每日)+(int_2))99.7,则
exp_val=1;

否则,如果SC=2,u_rep=1和((co3*(Daily**2))+(co_dem_3*Daily)+(int_3))您可能希望使用数据步数组而不是
编码:

data want;
  set have;

  array co(6) co1-co6;
  array co_dem(6) co_dem_1-co_dem_6;
  array int(6) int_1-int_6;

  do index = 1 to 6;

    if SC = index and u_rep = 1 then do;

      if ((co(index)*(Daily**2))+(co_dem(index)*daily)+(int(index))) > 99.7 then
        exp_val = 1;
      else
        exp_val = (( co_dem(index)*((co(index)*(Daily**2))+(co_dem(index)*daily)+(int(index)))/100;

    end;
  end;
run;

与其强迫我们进行文本比较以了解发生了什么变化,不如解释发生了什么变化。从您的一条评论中可以看出,与变量SC进行比较的数字正在发生变化。还有什么变化?它只是计算中使用的变量的名称?或者IF语句测试的条件中使用的变量是否也有变化?又是什么让您认为这需要任何宏代码?为什么不直接使用数组呢?你有没有一个
exp\u val
计算结果可能会被后面的结果所取代?我认为你不想要宏,而是想要数组。不管怎样,这里有一个关于宏的教程:这可能对OP很有帮助,但问题似乎是对免费劳动力的要求,这肯定是离题的。有些读者会不鼓励在这种情况下提供帮助,因为这会鼓励更多的离题材料,而这反过来又会产生更多的志愿工作来清理。