BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Purushottam_630
Calcite | Level 5

Hi Team,

 I hope you all doing well.

 

Suppose we have simple log file generated by 

 

data test;
set sashelp.class;
run;

 

how to extract above code from its log file.

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @Purushottam_630 

 

There is no general solution. The log content depends on current settings of LOG options, especially source, source2 and mprint, and in "worst case" there are no source statements written ti the log, only notes, warnings and errors.

 

But there are cases when it can be necesary. It happens to us all that we make stupid mistakes, and I have tried to delete a program by mistake and reconstruct it from a log file. It is a big task to write a program that reads the log and extracts source statements, especially from SAS EG logs, because SAS EG has a habit of wtiting tons of information to the log, most of it irrelevant for this purpose.

 

So the only way I can imagine is to take the log into an editor and delete all irrelevant information. This gives you plenty of time to be annoyed with yourself if it is a long log file with dozens of steps, macro loops etc, but it is quite easy in your example case: All source lines are written with a line number, so go only for these and end up with the the content of lines 28, 30 and 32.

 

Besides, this exercise is a good way of being familiar with the content of a SAS log. There is a lot of very useful information in the log. Step times give you ideas about where the code might be optimized, and a note of the type "missing values were generated" indicates a problem with your output that otherwise would go unnotized etc. So to understand a log file is an essential part of SAS education that is often neglected.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Copy and paste?

 

Or perhaps answering a slightly different but related question: you can use OPTIONS SPOOL;

 

But we're just guessing, you haven't explained why you want to do this, and if we knew the big picture including WHY then perhaps we could give an answer that doesn't depend on guessing what you need.

--
Paige Miller
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @Purushottam_630 

 

There is no general solution. The log content depends on current settings of LOG options, especially source, source2 and mprint, and in "worst case" there are no source statements written ti the log, only notes, warnings and errors.

 

But there are cases when it can be necesary. It happens to us all that we make stupid mistakes, and I have tried to delete a program by mistake and reconstruct it from a log file. It is a big task to write a program that reads the log and extracts source statements, especially from SAS EG logs, because SAS EG has a habit of wtiting tons of information to the log, most of it irrelevant for this purpose.

 

So the only way I can imagine is to take the log into an editor and delete all irrelevant information. This gives you plenty of time to be annoyed with yourself if it is a long log file with dozens of steps, macro loops etc, but it is quite easy in your example case: All source lines are written with a line number, so go only for these and end up with the the content of lines 28, 30 and 32.

 

Besides, this exercise is a good way of being familiar with the content of a SAS log. There is a lot of very useful information in the log. Step times give you ideas about where the code might be optimized, and a note of the type "missing values were generated" indicates a problem with your output that otherwise would go unnotized etc. So to understand a log file is an essential part of SAS education that is often neglected.

Purushottam_630
Calcite | Level 5
Thanks for suggestions.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 968 views
  • 2 likes
  • 3 in conversation