1) Yes you can write programs (scripts). No they can't be text files as FileMaker does not provide a text-editor type script editor.
2) It might be possible as export records can be used to both create and open a text file. I've used that method to create and execute both batch and VBScript files. But I do not know anything about SAS code so I don't know if that is sufficient to do what you need.