The SAS Output Delivery System and reporting techniques

Including date,time and username in ODS Filename

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

Including date,time and username in ODS Filename

Hi everyone,

So I got a bit stuck with this problem, I have the following coding:

%let path=C:\Users\User1\Documents\My SAS Files\Project;

%let person=%sysget(USERNAME);

%let systime_s = %sysfunc(timepart(%substr(&SysProcessId,1,16)x),time8.);

%let sysdate_t = &sysdate;

  ods _all_ close;

  ods listing close;

  ods pdf style=BStyle bookmarklist=hide file="&path./output_test&sysdate_t.&systime_s.&person..pdf" startpage = never;

  ods pdf; 

....

....

So what I want to achieve is to have the file name look something like this: output_test08JAN15123448User1.pdf - that is filename=output_test(todays date)(Todays time with seconds)(Username).pdf

Do you have any suggestions how to do this ?

Someone suggested the call symputx function but I'm not sure how to use it in this case.

Thank you


Accepted Solutions
Solution
‎01-08-2015 06:33 AM
Esteemed Advisor
Esteemed Advisor
Posts: 7,201

Re: Including date,time and username in ODS Filename

Well, formats are at: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001263753.htm

You may however need to do:  %sysfunc(compress(%sysfunc(time(),time8.),:.)) so

file="&path./output_test%sysfunc(date(),date9.)_t%sysfunc(compress(%sysfunc(time(),time8.),:.))_s%sysget(USERNAME).pdf" startpage = never;

View solution in original post


All Replies
Esteemed Advisor
Esteemed Advisor
Posts: 7,201

Re: Including date,time and username in ODS Filename

Hi,

You can use the %sysfunc syntax, with the date() and time() function and put them into whatever format you want.

%let path=C:\Users\User1\Documents\My SAS Files\Project;

ods _all_ close;

ods listing close;

ods pdf style=BStyle bookmarklist=hide file="&path./output_test%sysfunc(date(),date9.)_t%sysfunc(time(),tod5.)_s%sysget(USERNAME).pdf" startpage = never;

ods pdf; 

Contributor
Posts: 42

Re: Including date,time and username in ODS Filename

Thank you for the reply RW9 Smiley Wink.

It almost works perfectly, I think I just have to adjust the format of sysfunc(time(),tod5.) since currently it gives output_test08JAN2015_t13 and messes with the format of the file.

Can you recommend a format which will be in the form of 132750 (hhmmss) rather than the usual 13:27:50 (hh:mm:ss) format ?

Solution
‎01-08-2015 06:33 AM
Esteemed Advisor
Esteemed Advisor
Posts: 7,201

Re: Including date,time and username in ODS Filename

Well, formats are at: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001263753.htm

You may however need to do:  %sysfunc(compress(%sysfunc(time(),time8.),:.)) so

file="&path./output_test%sysfunc(date(),date9.)_t%sysfunc(compress(%sysfunc(time(),time8.),:.))_s%sysget(USERNAME).pdf" startpage = never;

Contributor
Posts: 42

Re: Including date,time and username in ODS Filename

I really need to scratch up with my date/time formats :smileyshocked:

It works like a charm now RW9, thank you very much.

Give this man a Bells !

Grand Advisor
Posts: 9,571

Re: Including date,time and username in ODS Filename

The file separator is \ (for windows) in &path, while it is / (for Unix) in file=" " , you can't combine them together .What OS is your SAS under ?

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 944 views
  • 6 likes
  • 3 in conversation