Hello @EinarRoed,
@EinarRoed wrote:
%macro rename; %if &program = 2A %then %do;
rename COLUMN_NAME_1 = COLUMN_NAME_2A;
%end;
%if &program = 2B %then %do;
rename COLUMN_NAME_1 = COLUMN_NAME_2B;
%end;
%if &program = 2C %then %do;
rename COLUMN_NAME_1 = COLUMN_NAME_2C;
%end; %mend rename; %rename;
Or maybe something like this:
if &program = 2A then do; rename COLUMN_NAME_1 = COLUMN_NAME_2A; end;
if &program = 2B then do; rename COLUMN_NAME_1 = COLUMN_NAME_2B; end;
if &program = 2C then do; rename COLUMN_NAME_1 = COLUMN_NAME_2C; end;
The first approach is syntactically correct (but could be simplified, see below), whereas the second approach is not (because the RENAME statement is not executable and the IF condition uses strings without quotes).
Instead of a macro you could use %SYSFUNC(IFC(...)) to create the RENAME statement dynamically:
%sysfunc(ifc(%sysfunc(findw(2A 2B 2C,&program)), rename COLUMN_NAME_1 = COLUMN_NAME_&program,));
... View more