* clog.sas Daniel Brockman 070729 Calc natural log for specified variables ; * tested 070729; %macro clog(vlist) ; /* * vlist = names of vars of interest, separated by spaces * * Invoke %clog within a data step. * * We calculate the natural logarithm on each date for each * var listed in vlist. We replace the value of the variable * with the log of the value. * * nb. This seems like a lot of macrofluff just to calculate a logarithm. * Might this be done in a more straightforward way in the calling program? * We do it in the macro because (1) we want to calculate the logs of * a general and unpredictable list of variables, (2) we cant do a macro * loop through the variables of interest in open code, (3) doing an * equivalent calculation with data step arrays seems more complex (tho * I didn't try it), because we don't know the order of the relevant * vars in the dataset. */ %let ii=0; %do %until (%scan(&vlist,%eval(&ii+1)) eq ) ; * loop the variable list ; %let ii=%eval(&ii+1); %let varii=%scan(&vlist,&ii); &varii=log(&varii); * replace value with natural log of value ; %end ; %mend clog ;