Creating a macro to first select all column_names from a data set into a list "dcodes",
then cycle through column_names, and if the column_name starts with "Diagnosiscode" (three such columns - Diagnosiscode1, Diagnosiscode2, Diagnosiscode3) apply simple logic based on the CONTENTS of the variable. If the contents of var Diagnosiscode1 is between the string "DC_101" and "DX_900" then perform some action (add a flag to another, different variable not in the :dcodes list - ("DX_GP01").
The log below clearly shows macro variable DIAG resolves to diagnosiscode1, yet the mlogic resolves to false.
When DIAG resolves to "Diagnosiscode1", or "Diagnosiscode2" or "Diagnosiscode3", the next step will fail -line 11 - (logically), as the string "Diagnosiscode1" is of course, NOT
ge 'DX_515' and le 'DX_910'. What I want is to assign DIAG to the CONTENTS of the variable "Diagnosiscode1" in data set Medical, so the logic would work if the data in that variable was in fact,
ge 'DX_515' and le 'DX_910'.
So there are two issues:
1. Why doesn't the logic in line 10 work the attached log.
2. Once the logic does work, how to change macro variable DIAG from line 8 so the CONTENTS of the name of that variable can be scanned for certain conditions, and if true, apply the logic to another variable.
A simpler way would be to just loop through the variables Diagnosiscode1, Diagnosiscode2 & Diagnosiscode3, one row at a time, and modify the contents of a second variable based on what was found.
There are many examples of looping through a SAS data set here, but the the output is always to another data set. I want to change values in the same data set.
THX.
1 %macro sum_flg(); 2 data med_grp; 3 length dx_GP01 2.; 4 set medical; 5 %local i diag; 6 %let i=1; 7 %do %while (%scan(&dcodes, &i) ne ); 8 %let diag = %scan(&dcodes, &i); 9 %put &diag.; 10 %if &diag. = ('diagnosiscode%') %then %do; 11 %if &diag. ge 'DX_515' and &diag. LE 'DX_910' %then %let Dx_GP01 = '1'; 12 %ELSE Dx_GP01 = '0'; 13 %end; 14 %let i = %eval(&i + 1); 15 %end; 16 %mend sum_flg
SYMBOLGEN: Macro variable DIAG resolves to diagnosiscode1
MLOGIC(SUM_FLG): %IF condition &diag. = ('diagnosiscode%') is FALSE
... View more