DATA Step, Macro, Functions and more

Outputting log to two locations

Accepted Solution Solved
Reply
Contributor
Posts: 74
Accepted Solution

Outputting log to two locations

Hi,

 

I want to keep my usual log as is AND output a part of it to another destination (text file) as well.  Any suggestions, without running the code over again using a different proc prinnto destination? My normal log is saved so I could also get the info from there but it would be a fair amount of manipulation just to get the bit I need. 

 

Thanks.


Accepted Solutions
Solution
‎09-28-2016 12:24 PM
Super User
Posts: 5,079

Re: Outputting log to two locations

Use the ALTLOG= system option, to generate a copy of the log.

View solution in original post


All Replies
Solution
‎09-28-2016 12:24 PM
Super User
Posts: 5,079

Re: Outputting log to two locations

Use the ALTLOG= system option, to generate a copy of the log.

Contributor
Posts: 74

Re: Outputting log to two locations

Excellent, thanks!

Contributor
Posts: 74

Re: Outputting log to two locations

Btw, is this alternate log file going to be appended?  I don't want it to be. 

Trusted Advisor
Posts: 1,369

Re: Outputting log to two locations

Are you running you program in batch mode or online?

 

If you run as batch add to the SAS execute line the ALTLOG= optionn and define the path and log name.

I think it will include also the part written by PROC PRINTTO, that you mentioned.

Contributor
Posts: 28

Re: Outputting log to two locations

Ok.

my understanding is that log_a is ok at 100 pct of log or rows has all output.

but the goal is log_b has only the section you are interested in.

if that is correct...

 

its possible to use "proc printto log="../newfolder/subseta_of_log.log  new;"

the key would be to strategically place this in your code and then -close- that log with a complementary "proc printto log=log; run;" once the section you need is over.

 

note: that this will split up your log into two files (two logs).

you still need ONE master log (if thats what you want)

you can do this by specifiying in command line executable or via config the altlog= option mentioned in the other suggestion.

while you would end up with 3 distinct logs.  1 would be the entire log (from altlog) the other two specified from your use of printto.

 

hth

 

zeke torres

www.wscug.com

 

 

 

so your code would read:

/*** top of code nothing run yet***/

 

proc printto log=log; run; *** this is redundant;

 

data work.test /* ... (step 1)*/;

*other code;

run;

 

proc print data=work.test (obs=30);

run;

 

/** all that will go to regular log **/

/** now the subset log **/

proc printto log="../newfolder/subseta_of_log.log  new; run;

 

proc /** something else ***/

run;

 

proc print /** something else **/

run;

 

/** now that you are done - set log back to default **/

proc printto log=log; run;

 

 

/*** rest of your code ***/

 

endsas;

Contributor
Posts: 74

Re: Outputting log to two locations

Yes, you understood my question correctly. It seems a lot easier to just have the normal log output (so no changes to current proc printto's), then use

 

* beginning of program *;

 

option altlog "destination.log";

 

* code that generates the log I want an extra copy of *;

 

option noaltlog;

 

* end of program *; 

 

 

I'm testing this right now.  

Contributor
Posts: 74

Re: Outputting log to two locations

Looks like I can't pop that into the middle of my program:

WARNING 11-12: SAS option ALTLOG is valid only at startup of the SAS System or startup of a SAS process. The SAS option is ignored.

Contributor
Posts: 28

Re: Outputting log to two locations

that message is correct.  

SAS options have orders of priority or availability to change based on where its being executed.

The use of this altlog as an "in code" option is limited.

Altlog is something you might need to do at config or command line.

 

you would need to configure your sas config file.

for example: im on linux and have a local .sasv9.cfg file.

in that file i can specify my altlog

 

in fact in our location we are currently monitoring some parts of our usage.

we have a global config option with an altlog.

 

so i know this can work - but your going to have issues if your trying to set that option in the wrong place.

 

if you are running EG - you can still configure your config file - but you would need to find it and create a copy.

 

hth

 

Contributor
Posts: 28

Re: Outputting log to two locations

ah - i think i see what you've tried.

 

again - options "in code" can only be set once.

 

my original suggestion still stands.

 

within your code: use the proc printto - this will allow you to split up your log to the parts you want to keep and part to ignore.

then outside of your code - use altlog - using the config or command prompt - this will enable you to keep an entire log.

 

hth

Contributor
Posts: 74

Re: Outputting log to two locations

Thanks but it looks like the easiest thing in this case is to just get the info I need from the original log.  The logs are saved in a standard process for all the programs and I don't want to mess with it. 

Super User
Super User
Posts: 6,498

Re: Outputting log to two locations

If you are confident that your job will not die in the middle part then you could copy the log back to the main log. It will look a little strange,but the information will be there.

 

So first redirect to a file

proc printto log='My new log file.log' new; run;

Then run the steps that you want to have the log information written to that file.  THen close it and copy it back into the real log.

proc printto log=log; run;

data _null_;
  if _n_=1 or eof then put '****** COPY OF LOG LINES WRITTEN TO SEPARATE FILE ****;
  infile 'My new log file.log' end=eof;
  input;
  put _infile_;
run;
Contributor
Posts: 74

Re: Outputting log to two locations

Thanks, interesting to know but too much trouble in this case I think. Or maybe I'm too lazy.  My first thought was "I swear these people are conspiring to make my life more difficult" ;-)

Super User
Posts: 9,671

Re: Outputting log to two locations

Why not use OS command COPY or function copy() .
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 13 replies
  • 493 views
  • 4 likes
  • 6 in conversation