BookmarkSubscribeRSS Feed
bream_bn
Fluorite | Level 6

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

6 REPLIES 6
Tom
Super User Tom
Super User

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.

Quentin
Super User

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.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
bream_bn
Fluorite | Level 6

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.

Tom
Super User Tom
Super User

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.

Tom
Super User Tom
Super User

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.

bream_bn
Fluorite | Level 6

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1609 views
  • 6 likes
  • 3 in conversation