-4

Would you convert these SAS codes to short MACRO as SC changes as 1 to 6?

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
;

I need macro version of the codes.

halfer
  • 19,824
  • 17
  • 99
  • 186
niloya
  • 1
  • 1
  • Instead of forcing us to text compare to see what is changing please explain what is changing. From your one comment it appears that the number that the variable SC is being compared to is changing. What else is changing? It is just the name of the variable used in the calculation? Or are there also changes in the variables used in the condition being tested by the IF statement? Also what makes you think this needs ANY macro code? Why not just use arrays? – Tom Nov 04 '19 at 17:50
  • Do you a `exp_val` computation result to be possibly superceded by a later one? – Richard Nov 04 '19 at 18:12
  • I don't think you want a macro, you want arrays instead. Regardless here's a tutorial on macros: https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md – Reeza Nov 04 '19 at 19:14

1 Answers1

1

You might want to use data step arrays instead of macro coding:

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;
Richard
  • 25,390
  • 3
  • 25
  • 38
  • This is probably helpful for the OP, but the question appears to be a request for free labour, and it is certainly off-topic. Some readers will discourage helping in these circumstances, since it encourages more off-topic material, and that in turn creates more volunteer work to clean up. – halfer Nov 05 '19 at 08:55