My friend is dying. What do I say to him?
There are several things I would do. I would pray for them and with them; I would listen to them; I would check on their family; I would grieve for myself outside their presence; I would support their faith.
Pray for her/him: Has s/he a fighting spirit or have they resigned themselves to dying? Their attitude would tell me whether to pray for a miracle or not. And when they do resign themselves, pray that s/he be graciously accepted into the arms of our merciful Savior as a lamb of Jesus' flock, and a sinner of his own redeeming.
Pray with her/him: Follow their lead as far as wishes go. If they wish to fight, embrace that. If they wish to go, there are many prayers in our hymnal that can easily be adapted.
Above all, listen to her/him. Let them share whatever they wish. You are in a sacred position of bearing witness to their life. Let them talk freely, and if appropriate, talk freely yourself. After all, you are their friend.
Check in with family members. Ask if there is some way you can help them. Listen to their concerns. If it seems right, pray with them. Include them in your prayers for your friend.
Grieve yourself, away from the friend and family. Do it by yourself or with friends and family. If that includes being angry with God, so be it. You are losing a friend. God can take it. Trust me on that.
Support their faith. Pray with them if you feel it. If you can, bring along music. A favorite hymn or song can be a refuge to both of you. Read favorite passages or stories from the Bible.
Be their friend. Share stories. Laugh at jokes. Cry together.
In summary, pray, listen, grieve, support. Know that God is there. To be their friend is sacred. Cherish it.