Hi ChrisNZ,
I tried to use your code without your tested data:
%let varlist= FOOD BEER SMOKE; option mprint; proc sql; create table IPW as select * %macro loop; %local i varname; %do i=1 %to 4; %let varname=%scan(&varlist,&i); ,(exp(sum(log(1+&varname/100))))-1 as &varname.1 format=percent8.2 %end; %mend; %loop from IP group by YR, WK having DAY=max(day) order by DATES ; quit;
And here is the log file:
NOTE: Line generated by the invoked macro "LOOP". 34 ,(exp(sum(log(1+&varname/100))))-1 as &varname.1 format=percent8.2 _ 22 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER. NOTE: Line generated by the macro variable "VARNAME". 34 1 _ 22 76 MPRINT(LOOP): * ,(exp(sum(log(1+FOOD/100))))-1 as FOOD1 format=percent8.2 ,(exp(sum(log(1+BEER/100))))-1 as BEER1 format=percent8.2 ,(exp(sum(log(1+SMOKE/100))))-1 as SMOKE1 format=percent8.2 ,(exp(sum(log(1+/100) )))-1 as 1 format=percent8.2 ERROR 22-322: Expecting a name. ERROR 76-322: Syntax error, statement will be ignored. 35 from IP 36 group by YR, WK 37 having DAY=max(day) 38 order by DATES ; NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements. 2 The SAS System 16:48 Monday, November 27, 2017 39 quit; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SQL used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
... View more