09-28-2016 12:11 PM
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.
09-28-2016 12:23 PM
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.
09-28-2016 12:30 PM
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.
so your code would read:
/*** top of code nothing run yet***/
proc printto log=log; run; *** this is redundant;
data work.test /* ... (step 1)*/;
proc print data=work.test (obs=30);
/** all that will go to regular log **/
/** now the subset log **/
proc printto log="../newfolder/subseta_of_log.log new; run;
proc /** something else ***/
proc print /** something else **/
/** now that you are done - set log back to default **/
proc printto log=log; run;
/*** rest of your code ***/
09-28-2016 12:36 PM
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 *;
* end of program *;
I'm testing this right now.
09-28-2016 12:43 PM
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.
09-28-2016 12:47 PM
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.
09-28-2016 12:50 PM
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.
09-28-2016 12:55 PM
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.
09-28-2016 02:14 PM
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;
09-28-2016 02:58 PM
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" ;-)
Need further help from the community? Please ask a new question.