greatplains <- unique(DT.GL[, list(ID_greatplains), keyby=storepart], by=NULL)

greatplains[setkey(copy(DT.storeparts), storepart), OA_storeid := storeid]

setnames(greatplains, "ID_greatplains", "greatplains_storeid")

setkeyIfNot(greatplains, "OA_storeid", organize=TRUE)
greatplains[setkey(copy(DT.stores), storeid), OA_storename := store_name]


setkeyIfNot(greatplains, "greatplains_storeid", "storepart", organize=TRUE)

write.csv(greatplains, "~/Desktop/greatplains_storeid.csv")