Scream loudly, and keep it up to attract attention and help from people near by.
If the attacker threatens you with a deadly weapon, and you come out of it alive, you took the proper course of action. During an armed attack, you must decide the proper course of action. There is no hard and fast rule as to self defense. You must consider your physical capabilities, your location, and your perceived chances of success. If you cannot escape, bide your time and look for another opportunity, a half-hearted attempt could be worse than no attempt at all.
Notify the police immediately, when you get the opportunity, and if there are witnesses, ask them to stay until police arrive.
And finally, if a crime occurs, report it. When you report a crime and all the facts about it, it helps the police to assign officers in the places where crimes are occurring or where they are most likely to occur. If you don't report a crime, this allows the criminal to operate without interference. Tell the police what you know. No fact is too trivial.