07-09-2015 06:32 PM
If you have just run a program in base SAS you can press the F4 key and code will be "recalled" into the program editor.
Otherwise you can highlight lines in the log and copy/paste into the editor, which will likely require some editing to remove notes.
Or save the log to a text file and edit with any editor.
07-10-2015 04:21 AM
If you want to extract the SAS Code in a log file and store it in a dataset then the below code will help you
In logs the SAS code will be preceded with line numbers. So first pick the lines which are starting with numbers. Here I stored the data in the variable Code1.
If you need only the SAS Code with out the line numbers then use substr to extract only the code leaving the line numbers. Here I stored the same in the variable Code.
There will be blank lines in the code and the blank spaces will be stored in the dataset as observations.We can exclude these observations by using the if condition.
input dat $1000.;
dat = _infile_;
if substr(left(_infile_),1,1) in ('1','2','3','4','5','6','7','8','9','0') then code1 = _infile_;
code = substr(code1,index(code1," "));
if code ne " ";
If you want to export the code into any flat file then
proc export data = SASCode outfile = "xxx" dbms= xxx replace;