Hello,
I am quite new using loops and really want to understand it better.
I have an excel file with 11 sheets, I only need a couple sheets from it and need to rerun it everyday with new data but the same variables so am I am trying to write an efficient script to be able to complete what I need to do. For each of the sheets there are patient identifiers but they come in with different column names which is making it difficult to merge when importing within one loop.
If the column that I want to merge on is column_A, but in each sheet is called "column_AA" "column_AB" "columnAC" respective for the Sheet A, Sheet B, Sheet C
What I have so far to import the data in.

Code:
local sheets "Sheet_A Sheet_B Sheet_C"
foreach y in `sheets'{
    import excel using "data_set.xls", sheet(`y') firstrow clear
    save "`y'.dta",replace 
    }
How might I be able to add in a command to rename the column names to a similar one so then I can merge them all?

I was thinking of adding a loop inside it or a second loop after, but then the correct column_AB wouldnt match up with the correct sheet.
this is what i was thinking but doesnt really work
Code:
local variable "column_AA column_AB columnAC" 
        foreach t in `variable'{
        use "`y'.dta", clear
        rename `t' column_A
        }
Thanks for your help/advice/response!

-Ben