Help using Base SAS procedures

saving macro compilation log using proc printto

Reply
Contributor
Posts: 27

saving macro compilation log using proc printto

Hi All,

 

I was trying to save my logs using proc printto and noticed that all the macros that i compile are not coming into the log unless i call them or i run some procedures after compiling a macro. I do not understand why i do not get the compiled macro statement into the permanent file as it comes in standard LOG location. Can somebody please help me understanding this.

 

For Example:-

 


proc printto log="abc.txt";
run;


%macro abc;
%put anbc;
%mend;

 

 

If i use the DM statement, i get all log contents for the session. Which one is better to use??

 

dm 'log; file "abc.txt"';

Super User
Super User
Posts: 6,495

Re: saving macro compilation log using proc printto

Can you provide and example?

Because it works fine for me.

filename log1 temp;
proc printto log=log1 new ; run;
%macro mymac;
  %put &sysmacroname;
%mend mymac;
proc printto log=log; run;

data _null_;
  infile log1;
  input ;
  put _infile_;
run;
Contributor
Posts: 27

Re: saving macro compilation log using proc printto

That is may be you have few statements after macro compilation. Will only the below code gives you anything in the log??

 

filename log1 temp;
proc printto log=log1 new ; run;
%macro mymac;
  %put &sysmacroname;
%mend mymac;

Super User
Super User
Posts: 6,495

Re: saving macro compilation log using proc printto


bharathtuppad wrote:

That is may be you have few statements after macro compilation. Will only the below code gives you anything in the log??

 

filename log1 temp;
proc printto log=log1 new ; run;
%macro mymac;
  %put &sysmacroname;
%mend mymac;


If you run that program then your SAS log will end at the PROC PRINTTO statement and the macro defintion will go to the temporary file defined by the FILENAME statement.  All of the log output will go to that file until you direct it somewhere else by calling PROC PRINTTO again.

 

 

Contributor
Posts: 27

Re: saving macro compilation log using proc printto

Okay, lets say i am creating a permanent file instaed of temp file. Then also i do not see the compiled statements as i woould see in the standard log location (Log window). Should i use printto again to redirect?? Why is this behaviour??

Super User
Super User
Posts: 6,495

Re: saving macro compilation log using proc printto

I really do not understand the question. Obviously you would use different filename in the PROC PRINTTO statement to direct the SAS log to where you want.  You do not need to use a FILENAME statment as you can use a quoted physical path in the PROC PRINTTO statement instead of fileref.

 

Whatever SAS writes to the LOG can be redirected using PROC PRINTTO. So the statements that define a macro are written to the log as the code statements are encountered, just like any other SAS code that you run.  This means that they now longer appear in the normal SAS log until you turn off the redirection.   If you want you could use something like the extra data step in my example to read back in the lines written to the other file and also display then in the "real" SAS log.

 

It is not like using SAS Display Manger.  There is no log "window" that you can save after the fact to a file.  You need to direct SAS to write the log to the file BEFORE running the lines of code. You can then turn off the redirection when you want to start sending the log messages to the normal log file again.

Contributor
Posts: 27

Re: saving macro compilation log using proc printto

My question here is very simple. When you compile a macro, you would see the macro in default log window, but you will not see it in the external log file you created using proc printto unless you call it or execute another data or proc step. Why??

Super User
Super User
Posts: 6,495

Re: saving macro compilation log using proc printto

[ Edited ]

You will need to show the log of the code you ran where it did not work. The example I posted confirms that it works fine.

Here is an example SAS log from redirecting the log to a file and then stopping the redirection and then reading the external file back in and dumping it to the log window to prove that it wrote something there.  You can see that lines 541 to 544 have the definition of the macro MYMACRO.

537  %let fname=%sysfunc(pathname(work))\external_file.log ;
538  * This is from BEFORE the first PROC PRINTTO;
539  proc printto log="&fname" new ; run;

NOTE: PROCEDURE PRINTTO used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


551  * This is from AFTER the SECOND PROC PRINTTO;
552  * Dump what was written to the external file;
553  data _null_;
554   infile "&fname" ;
555   input;
556   put 'From LOG1-> ' _infile_;
557  run;

NOTE: The infile "...\external_file.log" is:

      Filename=...\external_file.log,
      RECFM=V,LRECL=32767,File Size (bytes)=632,
      Last Modified=14Apr2017:10:41:15,
      Create Time=14Apr2017:10:39:56

From LOG1-> NOTE: PROCEDURE PRINTTO used (Total process time):
From LOG1->       real time           0.00 seconds
From LOG1->       cpu time            0.00 seconds
From LOG1->
From LOG1->
From LOG1-> 540  * This is from AFTER the first PROC PRINTTO;
From LOG1-> 541  %macro mymacro;
From LOG1-> 542  %global testing;
From LOG1-> 543  %let testing=I have run the macro &sysmacroname;
From LOG1-> 544  %mend mymacro;
From LOG1-> 545  data x;
From LOG1-> 546    do i=1 to 10;
From LOG1-> 547      output;
From LOG1-> 548    end;
From LOG1-> 549  run;
From LOG1->
From LOG1-> NOTE: The data set WORK.X has 10 observations and 1 variables.
From LOG1-> NOTE: DATA statement used (Total process time):
From LOG1->       real time           0.01 seconds
From LOG1->       cpu time            0.01 seconds
From LOG1->
From LOG1->
From LOG1-> 550  proc printto log=log; run;
From LOG1->
NOTE: 24 records were read from the infile "...\external_file.log".
      The minimum record length was 0.
      The maximum record length was 62.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


 

Contributor
Posts: 27

Re: saving macro compilation log using proc printto

Can you please not use any datastep or proc step after compiling a macro, open the permanent log file physically and see.

Super User
Super User
Posts: 6,495

Re: saving macro compilation log using proc printto

I have no idea what you are asking.

If you use PROC PRINTTTO to redirect the log then it will continue to send all log messages to there until you run another PROC PRINTTO (or end SAS).

Ask a Question
Discussion stats
  • 9 replies
  • 192 views
  • 0 likes
  • 2 in conversation