BookmarkSubscribeRSS Feed
luca87
Obsidian | Level 7

Hi,

is there any way to print in the log by pointing to a saved .sas code?

 

Thanks

Luca

7 REPLIES 7
PaigeMiller
Diamond | Level 26

Your question is unclear. "Print in the log" doesn't have an obvious meaning to me, especially since your title talks about printing .sas code. "... by pointing to a saved .sas code" does not have an obvious meaning to me. The whole things needs more clarity.

--
Paige Miller
Tom
Super User Tom
Super User

@luca87 wrote:

Hi,

is there any way to print in the log by pointing to a saved .sas code?

 

Thanks

Luca


Can you clarify what your question is?

Both a SAS program file (what is in a .sas file) and a SAS LOG (where SAS writes when it runs) are text files.  You can print them with any tool that can print a text file.  An simple text editor should be able to let you view and print such a file.

 

A saved program file does imply that there is any saved log of when it was last run.  The log is normally saved as a different file. 

 

If you run SAS directly from the command line it will normally name the log file it generates by replacing the .sas extension of the program file you told it to run with .log.

ErikLund_Jensen
Rhodochrosite | Level 12

Hi @luca87 

A log is created by SAS during program execution. The log contains a mix of 2 things: blocks of code lines written as they are met in the program stack and notes written after each block is executed. Listing of code lines in the log is controlled by 2 options: Source/Nosource and Source2/Nosource2.

 

The default is Source and Nosource2, which means that first level code, iso code that is contained in the program is listed, while second level code, wiich is SAS program files included in the code with a %include statement or the code in Autocall Macros, is not.

 

An administrator may have turned Source off by default in your setup, so you never see any code lines in the log, only the notes.  But you can override that with the statement Options Source as first line in your program. Similar with Source2, unless it is rectricted by the administrator. 

 

You cannot list code that is not included in the program this way, because the log is a product of execution. In principle, you can write a data step to read the file and list the content to the log, but I suppose that is not what you want.

luca87
Obsidian | Level 7
I apologise for my lack precision in my question.
I have a sas code saved in a name.sas file which contains for example a sql proc.

I would like to find out if there is a way to print the code without executing it in a log or a result or whatever. I would like to see this sql proc written but not executed.
I need it to show how different extractions are made.
Tom
Super User Tom
Super User

If you just want to dump a text file to the SAS log just use a data step.

data _null_;
  infile 'name.sas';
  input;
  put _infile_;
run;
ShukWork
Calcite | Level 5

Tom's example is really helpful if you have a SAS program referenced in a %INCLUDE statement and you don't know where the path is.

Kurt_Bremser
Super User

@luca87 wrote:
..... I would like to see this sql proc written but not executed.

You already have all the PROC SQL text in the .sas file.

What it actually does depends on the data it runs against, and to see that, you have to execute it with real data, period.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1427 views
  • 6 likes
  • 6 in conversation