I have a stored process which I run from an excel report. All the sp does is execute a code module which loads data to a table. The sp runs fine but I need to save the log and don't know how to get it to output into the excel I execute from or even place a log somewhere on the unix server. We are running SAS 9.4 on unix.
How can I do this?
Thanks,
Elliott
Yes, you can use the macro language to generate a timestamp, like:
%put %sysfunc(today(),yymmddn8);
20170614
%put %sysfunc(datetime(),b8601dt15);
20170614T104305
Use like:
proc printto new log="/somedir/mylog_%sysfunc(datetime(),b8601dt15).log";
run;
The stored procss server usually has macro variables with name of the stored process, name of the user, etc. So sometimes I will put those into the name of the log file as well. I all the log files for X days, in case someone reports a problem. Having the name of the stored process and the user in the log file makes it easier to find the appropriate log.
Note some server admins might not like this approach, because if they have configured STP logs to go to a central location, using PROC PRINTTO to redirect the log prevents the log from being written wherever they expect it. If ALTLOG could be executed within a session, I would use that instead.
You can use PROC PRINTTO at the beginning of your STP to send the log file somewhere.
proc printto new log="/somedir/mylog.log";
run;
*main code here;
proc printto; *restore defaults;
run;
I haven't done much with calling stored processes from Excel, but I would think if you want to display it in the Excel, there must me some way to steam the contents back to Excel. Of course not sure I would want to actually SEE a log file viewed in an Excel sheet....
If you don't need a permanent log file, you can send it to work dir with log="%sysfunc(pathname(work))/mylog.log".
Thanks Quentin, this is what I need.. is there any way to append a date stamp onto the log name when it outputs?
Thanks,
Yes, you can use the macro language to generate a timestamp, like:
%put %sysfunc(today(),yymmddn8);
20170614
%put %sysfunc(datetime(),b8601dt15);
20170614T104305
Use like:
proc printto new log="/somedir/mylog_%sysfunc(datetime(),b8601dt15).log";
run;
The stored procss server usually has macro variables with name of the stored process, name of the user, etc. So sometimes I will put those into the name of the log file as well. I all the log files for X days, in case someone reports a problem. Having the name of the stored process and the user in the log file makes it easier to find the appropriate log.
Note some server admins might not like this approach, because if they have configured STP logs to go to a central location, using PROC PRINTTO to redirect the log prevents the log from being written wherever they expect it. If ALTLOG could be executed within a session, I would use that instead.
Thank you!!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.