You can open up a level in which to write an Xcas program with the menu item Prg▸New program (which is equivalent to Alt-P). If you select this item, you will be prompted for information to fill out a template for a program and then be left in the program editor.
At the top of the program editor there will be menus and buttons, at the far right will be a Save button that you can press to save the program. The first time you save a program, you will be prompted for a file name, you should choose a name ending in .cxx. Once a program is saved, the file name will appear to the right of the Save button. If you want to save the program under a different name, you can use the Prog▸Save as item from the program editor menu.
To insert a previously saved program, you can use the Prog▸Load item from the program editor menu.