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
PROC Star

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.

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.

View solution in original post

4 REPLIES 4
Quentin
PROC Star

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

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
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
PROC Star

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.

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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