BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jimksas
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

View solution in original post

7 REPLIES 7
Scott_Mitchell
Quartz | Level 8

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

jimksas
Calcite | Level 5

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

Scott_Mitchell
Quartz | Level 8

Did you execute the Proc Format code first?

Kurt_Bremser
Super User

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

Tom
Super User Tom
Super User

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

jimksas
Calcite | Level 5

No Scott, i didn't run it Smiley Sad  ...may be that's why...- Thanks

Thanks all for your detail...many ways to do it... 🙂

I am using RW9 solution...

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!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 7 replies
  • 2247 views
  • 6 likes
  • 5 in conversation