/**************************************************************** * * DoOver: iterate over list of values * * Syntax: * %DoOver(list,text,sep=%str( ),space=%str( ),substchar=#,numchar=); * * Parameters: * list = list of values * text = text into which to substitute values * sep = separator character(s) in list (default=space) * space = text to put between output values (default=space) * substchar = character (or string) to substitute with value * numchar = character (or string) to substitute with list number * * Iterates over the values in the list, elements separated by one or more characters of * sep (default is space). In the text, the substchar is substituted with the list value. If * a numchar is specified, this will be substituted with the running number (1,2,...). * * The text is unquoted when output, and occurences of substchar within %nrstr or * %quote blocks will be substituted. The text may thus contain even lengthy SAS * code. * * Example: * data temp; * set temp; * %DoOver(age height length,%nrstr(log_#=log(#);); * label %DoOver(age height length,%nrstr(log_#="Logarithm of #")); * run; * * Requires: %Substitute * ****************************************************************/ %MACRO DoOver(list,text,sep=%str( ),space=%str( ),substchar=#,numchar=); %LOCAL i txt sep_; %Substitute(&substchar.,%nrstr(&txt.),var=text) %IF %bquote(&numchar)^=%str() %THEN %Substitute(&numchar.,%nrstr(&i.),var=text); %LET i=1; %LET sep_=; %DO %WHILE ("%SCAN(&list,&i,&sep)"^=""); %LET txt=%scan(&list,&i,&sep);%* ;&sep_.%unquote(&text) %LET i=%eval(&i+1); %LET sep_=&space; %END; %MEND DoOver;