Your SAS programs, embedded in web apps and elsewhere

Need SAS Log when executing Stored Process from MS Excel

Accepted Solution Solved
Reply
Contributor
Posts: 74
Accepted Solution

Need SAS Log when executing Stored Process from MS Excel

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


Accepted Solutions
Solution
‎06-14-2017 02:00 PM
PROC Star
Posts: 1,324

Re: Need SAS Log when executing Stored Process from MS Excel

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.

View solution in original post


All Replies
PROC Star
Posts: 1,324

Re: Need SAS Log when executing Stored Process from MS Excel

[ Edited ]

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".

Contributor
Posts: 74

Re: Need SAS Log when executing Stored Process from MS Excel

Thanks Quentin,  this is what I need.. is there any way to append a date stamp onto the log name when it outputs?

 

Thanks,

Solution
‎06-14-2017 02:00 PM
PROC Star
Posts: 1,324

Re: Need SAS Log when executing Stored Process from MS Excel

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.

Contributor
Posts: 74

Re: Need SAS Log when executing Stored Process from MS Excel

Thank you!!

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 431 views
  • 0 likes
  • 2 in conversation