It is probably easier to write a new sketch rather than combine two existing sketches. Just use the existing sketches for ideas.
I you really want to try to merge the two sketches this general approach may help
// variables from sketchA
// variables from sketch B
void setup() {
// setup stuff from sketch A
// setup stuff from sketch B
}
void loop() {
// functionA();
// functionB();
}
void functionA() {
// code from loop() part of sketch A
}
void functionB() {
// code from loop() part of sketch B
}
...R