Your SAS programs, embedded in web apps and elsewhere

Proc Printto Logging Options

Reply
Contributor
Posts: 28

Proc Printto Logging Options

Is it possible to use the same type of logging options in code as it is when setting the log at the command line? I would like ensure that I have unique log names as my stored process is called frequencies and I have had problems in the past. I know I could create a new variable which I could append to the proc printto log= statement but it would be more convenient to use similar options. Below is a link to the documentation which shows the command line options, precisely the "Details" section.. http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002303556.htm

p

Super User
Super User
Posts: 6,502

Re: Proc Printto Logging Options

Are you asking how to generate a filename that reflects the current time?

%let ts=%sysfunc(today(),yymmddn8.);

proc printto log="myfile&ts..log";

You can use &SYSDATE9 and &SYSTIME to get the date and time that the SAS session started or use TODAY(),TIME() or DATETIME() to get the current time.  You can use formats or string manipulation to pull out whatever parts of the name you want.

I find that when creating filenames using dates it is best to use YYMMDD formats because then the filenames will sort naturally into date order.

PROC Star
Posts: 1,237

Re: Proc Printto Logging Options

Hi,

I agree with Tom.  Recently I've been doing date-times with the b8601dt format, which returns yyyymmddThhmmss.  (e.g. 20120611T083038 for 8:30 am on June 11 2012.

I'm still new to stored processes. I've been playing with using &_prorgram and &_Username in the name of the file as well, and dumping all my stored process logs in one folder.  One caveat is that I think &_username may be a generic value if user is not defined in metadata.  Also been thinking about having a standard put statement at the stop of every stored process to write key values to the log (e.g. all user-specified parameters, maybe even just all macro variables).  So that later can parse logs to looks for trends in how users invoke different stored processes.  Or maybe just append these values to a dataset every time a stored process is invoked....

filename logfile "/logs/%sysfunc(compress(%scan(&_program,-1,/)_&_UserName._%sysfunc(datetime(),b8601dt))).log";
proc printto log=logfile new;
run;

--Q.

Contributor
Posts: 28

Re: Proc Printto Logging Options

I have our Stored Process setup as Web Services, these services can get called concurrently by different users and so I was hoping to be able to use the %v option to give each log name a unique name every time. I use a form of the date time currently but I do like the way the b8601dt format displays and will likely to begin using that to make my log names unique.

Super User
Super User
Posts: 6,502

Re: Proc Printto Logging Options

If you SAS process is running on Unix and you can call system commands then look at the mktemp command.  That should let you generate a unique filename.

Super User
Super User
Posts: 6,502

Re: Proc Printto Logging Options

If your SAS process is running on Unix and you can call system commands then look at the mktemp command.  That should let you generate a unique filename.

Contributor
Posts: 28

Re: Proc Printto Logging Options

Thanks for the info I will look into the mktemp command as an alternative.

Ask a Question
Discussion stats
  • 6 replies
  • 602 views
  • 6 likes
  • 3 in conversation