Dear community,
With the following code I want to add new column to existing dataset by defining array and this array should add value if my criteria met. For instance suppose that I have record and this record has 1 for first and third columns. If value is 1 then I expect my array to add corresponding numeric value to this rules (i.e 20, 30 , what is defined in points table). However following code updates each matched column's value with correspondingfinal loop value (my array loop finishes at 5 and if Rule5's value is 100, than rest of the matched columns updated with 100). How to preserve each rule's own value and not to replace previous one's value with the next updated one?
data points(DROP= i); do i=1 TO 10; COL1 = CATS("Rule",i); COL2 = 10 * i; OUTPUT; END; RUN;
data base (drop=i); do i=1 TO 5; CL_NO = i; output; end; run;
data base2 (drop=i); do i=1 to 5; CL_NO = i; Rule1 = RAND("integer",0,1); Rule2 = RAND("integer",0,1); Rule3 = RAND("integer",0,1); Rule4 = RAND("integer",0,1); Rule5 = RAND("integer",0,1); output; end; run;
proc sql; create table base3 as select a.CL_NO, Rule1, Rule2, Rule3,Rule4,Rule5 from base a left join base2 b on a.cl_no = b.cl_no; quit;
options mprint; %macro main_macro();
%macro another_macro(inp_trig,inp_index);
data out_&inp_index.; set points; where COL1 = "&inp_trig."; run;
%global puan_&inp_index.;
proc sql; select col2 into : point_&inp_index. from out_&inp_index.; quit;
%mend;
DATA RESULT; SET base3; ARRAY RULE[*] Rule:; ARRAY RESULT[5] RESULT1-RESULT5;
DO i=1 to 5;
temp_result = CATS("Rule",i); call symputx("temp_result_macro",temp_result,"G"); call symputx("index",i,"G");
if RULE[i] = 1 then do;
call execute('%another_macro(&temp_result_macro,&index)');
result[i] = &&point_&index.;
end;
end;
run;
%mend;
%main_macro;
Thank you
... View more