BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Elliott
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

View solution in original post

4 REPLIES 4
Quentin
Super User

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

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
Elliott
Obsidian | Level 7

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

 

Thanks,

Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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