Hello,
i want to set up filename ending with datetime as below on daily report...please help...
filename xyz_abc_20140710112330.txt
/*filename xyz_abc_yyyymmddhhmmss.txt*/
Thank you in advance...
What does it say in the log with options mlogic sybolgen mprint. I would imagine that you would at least need in the filename statement %trim(&fname) to avoid extra spaces. Personally I wouldn't go with formats, but it depends on where you are getting the date and time from, is it today() function, a dataset etc.
data _null_;
call symput('FNAME',compress(put(today(),yymmdd10.),"- ")||compress(put(time(),time8.),": "));
run;
%put xyz_abc_&fname.;
How about this?
Create a custom format.
PROC FORMAT;
PICTURE YMDDT OTHER='%0Y%0M%0D%0H%0M%0S' (DATATYPE=DATETIME);
RUN;
Create macro variable containing the date and time of right now and use custom format.
DATA _NULL_;
CALL SYMPUTX ("FNAME","XYZ_ABC_"||TRIM(LEFT(PUT(DATETIME(),YMDDT.))));
RUN;
%PUT &FNAME.;
YMDDT.
is giving error...format cannot ound and could not be loaded...
i am trying create macro for only datetime function not with filename, so i can write down like this....
filename xyz_abc_&fname.txt
What does it say in the log with options mlogic sybolgen mprint. I would imagine that you would at least need in the filename statement %trim(&fname) to avoid extra spaces. Personally I wouldn't go with formats, but it depends on where you are getting the date and time from, is it today() function, a dataset etc.
data _null_;
call symput('FNAME',compress(put(today(),yymmdd10.),"- ")||compress(put(time(),time8.),": "));
run;
%put xyz_abc_&fname.;
Did you execute the Proc Format code first?
data _null_;
now=datetime();
dat1=datepart(now);tim1=put(timepart(now),time8.);
filname='xyz_abc'!!put(dat1,yymmddn8.)!!substr(tim1,1,2)!!substr(tim1,4,2)!!substr(tim1,7,2)!!'.txt';
call symput('filnam',filname);
run;
filename outfile "/path_to_the_directory/&filnam";
I would just use B8601DT. format. If you really do not want the T between the date and time parts you could use COMPRESS() function to remove it.
%let dt=%sysfunc(datetime(),B8601DT);
%put dt=&dt;
dt=20140710T083935
%let filename=xyz_abc_%sysfunc(compress(&dt,T)).txt ;
%put filename=&filename ;
filename=xyz_abc_20140710083935.txt
You can now use anywhere a physical filename is required.
filename outfile "&filename" ;
file "&filename" ;
No Scott, i didn't run it ...may be that's why...- Thanks
Thanks all for your detail...many ways to do it... 🙂
I am using RW9 solution...
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.