So my dataset is in long format. I am trying to calculate the change of scores from baseline. I have created the following macro: %MACRO CHANGE(score,var); if visit=1 then &score._bl=&score; retain &score._bl; else &score._chg=&score-&score._bl; label &score._bl="&var at baseline" &score._chg="Change in &var from baseline"; %MEND CHANGE; So the issue I am running into, is that if a patient did not have baseline (visit) assessment, the code takes the last known baseline value from another patient, which I do not want. This is my sample data (based after running the macro above and looking at my data): ID Visit Score (&score) Score at Baseline (&score._bl) Change in Score from Baseline 1 1 12.5 12.5 1 2 20 12.5 7.5 2 2 26 12.5 13.5 So as you can see highlighted in red, ID=2 did not have a visit 1, he joined the study at visit 2. But when the macro calculated the change of score, the previous retained value is used. THis is not right. Is there a way I can fix this? Alternatively, I can create a new dataset with just the baseline values by ID, rename the variables and merge it back in. But I am hoping there is a more efficient way to do this. Reason why I am using a macro approach is because I will be doing this with multiple scores. I would like to thank everyone in advanced who provided feedback on this.
... View more