Hi all, I have background on VBA programming, however, I got trouble in using macro in SAS. It seems macro is not totally like to create a function. Can anyone help me, please? There are many fields in my dataset and I would like to pro-rata adjust the value of them with a total value. So, I would like to prepare a function/subroutine/macro. Problem 1. I wounder why the value of dummy will be changed when the value of n1 changed. >>>%let dummy=sum(&n1,&n2,&n3); >>>&n1=&n1/&dummy*&c; >>>&n2=&n2/&dummy*&c; *<<< the value of dummy is changed, due to the n1 changed in last row; Problem 2. I tried to add the function %EVAL but failed, the error is when the co1 pass to the macro, the compiler convert the col1 to string the EVAL only can handle numeric number ================================== Here is the example code. data testdata; input col1 col2 col3 col4 col5; datalines; 1 1 3 2 2 2 2 4 5 5 10 10 3 7 7 ; run; %MACRO prorata3(c,n1,n2,n3); %let dummy=sum(&n1,&n2,&n3); &n1=&n1/&dummy*&c; &n2=&n2/&dummy*&c; *<<< the value of dummy is changed, due to the n1 changed in last row; &n3=&n3/&dummy*&c; %MEND prorata3; data temp; set testdata; %prorata3(1000,col1,col2,col3); /* if there exists any other condition later %prorata4(10000,col2,col3,col4); %prorata5(400,col1,col2,col3,col4,col5); */ run; =============================================== The expected output should be 200 200 600 2 2 250 250 500 5 5 435 435 130 7 7 But the output is 200 5 14 2 2 250 8 15 5 5 435 22 7 7 7
... View more