It depends on your case (financial situation) and the dead line for your debt to be paid.
Being in debt doesn't necessary mean one is not allowed to do charity (sadaqah), but if one has a debt or loan and is in (good) hope to be able to pay it until the deadline there's no harm in doing charity.
But if not then one shouldn't do sadaqah as in the sunnah:
Delay (in the payment of debt) on the part of a rich man is injustice, and when one of you is retired to a rich man, he should follow him.
(see for example in sahih al-Bukhari, sahih Muslim and al-Muwatta')
"The best charity is that which is practiced by a wealthy person. And start giving first to your dependents." (Sahih al-Bukhari)
Note that in his introduction for the chapter -Chapter: The wealthy only are required to give in charity- including the last (linked) hadith imam al-Bukhari wrote the following:
Whoever gives charity when he is in need or his family is in need, or when he owes a debt, should understand that the debt is more deserving of being paid off than charity, freeing a slave or giving a gift, and that (charity or gift) is invalid. He does not have the right to waste people’s money. The Prophet (blessings and peace of Allah be upon him) said: ‘Whoever takes people’s wealth intending to waste, Allah will destroy him.” (source of the translation: islamqa #145862)
Imam an-Nawawi in his al-Minhaj (the commentary on sahih Muslim) held the opinion that it is better not to do charity as long as in debt.
You may also read in both sahihs the complain of some poor sahib who where not able to do charity (see for example in sahih Muslim) the messenger of Allah gave them a workaround and explained that not every charity is a good deed!