Hi,
I am trying to program a code that goes through variables pr1-25 (procedure codes) to create a new variable that corresponds to these codes prday1-prday25 where prday contains the day of the procedure performed.

This is the code I am using
gen time_procedure=.
foreach x of numlist 1/25 {
replace time_procedure=prday`x' if i10_pr`x' == "ddd" | i10_pr`x' == "ffff"
}

The issue is that through 1-25 there might be more than one procedure with ddd or ffff codes, so I want the code to run but stop replacing the days if it encountered further procedure through 25
for example
if pr1 is ffff it replaces the day with "5" which is the value in prday1
if the same record has pr5 as ddd or ffff, it will replace the "5" with "10" which is the code in prday5
I don't want that replace to happen, is there anyway to do that?