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

 

I am trying to create a file which has a date stamp appended to the file name. I've created my parameter, correctly I think.

 

/* Parameter default value(s) for File date test */
%let datetimef_label = Current date and time (June 7, 2019 04:32:54 PM);
%let datetimef = 07Jun2019 16:32:54;
%let datetimef_rel = T0m;

 

Then my precode

 

/*---- Start of Pre-Process Code ----*/

%let datetimef=%sysfunc(datetime(),yymmddd10.);
/*---- End of Pre-Process Code ----*/

 

 

Yet when I run it I get the following error in the log: (The physical  location is a real place. I use it for other jobs identical to this one except those do not have the datetime parameter.)

 

This physical location works on the job that works.  file "\\As-i2i01\udp_in\Input\PAT9.upd" dlm='|';

 

This one fails on the job with the datetime.      file "\\As-i2i01\udp_in\Input\FDTTEST_&datetimef.upd" dlm='|';

 

 

 

This is the log:

 

195 data _null_;
196 set &SYSLAST;
197 attrib RecordType length = $12;
198 attrib RecordAction length = $8;
199 attrib EventTypeID length = 8;
200 attrib SourceID length = $8;
201 attrib Value length = $255;
202 attrib EventCount length = $8;
203 attrib LastEventDate length = $8;
204 attrib LastSourceEditDate length = $8;
205 quote='"';
206 file "\\As-i2i01\udp_in\Input\FDTTEST_&datetimef.upd" dlm='|';
207
208 put
209 quote +(-1) RecordType +(-1) quote
210 quote +(-1) RecordAction +(-1) quote
211 quote +(-1) EventTypeID +(-1) quote
212 quote +(-1) SourceID +(-1) quote
213 quote +(-1) Value +(-1) quote
214 quote +(-1) EventCount +(-1) quote
215 quote +(-1) LastEventDate +(-1) quote
216 quote +(-1) LastSourceEditDate +(-1) quote
217 ;
218
219 run;

ERROR: Invalid physical name.

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @gsmith 

 

The problem is caused by the macro variable datetimef. You use a date-format on a datetime-value, so you ask SAS to take the number of seconds since 10 jan 1960 - right now it is 1875696783, and use it as the number of days. The largest date value in SAS is 2936547, so your value is larger than the max. date, and the formatted value becomes  a string of stars instead of a formatted date.

 

Have a look at these 3 examples. Only the last gives a valid filename:

 

192  %let datetimef=%sysfunc(datetime(),yymmddd10.);
193  %put &=datetimef;
DATETIMEF=**********
194
195  %let datetimef=%sysfunc(datetime(),datetime22.0);
196  %put &=datetimef;
DATETIMEF=09JUN2019:10:56:57
197
198  %let datetimef=%sysfunc(date(),yymmddd10.);
199  %put &=datetimef;
DATETIMEF=2019-06-09

By the way - You don't get the filename you expect, because the dot disappears. It is taken as a terminator for the macro variable, so you don't get the filetype separated from the file name. You need 2 dots:

 

201  data _null_;
202      a =  "c:\temp\FDTTEST_&datetimef.upd";
203      put a;
204
205      a =  "c:\temp\FDTTEST_&datetimef..upd";
206      put a;
207  run;

c:\temp\FDTTEST_2019-06-09upd
c:\temp\FDTTEST_2019-06-09.up

 

View solution in original post

3 REPLIES 3
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

have you set the options to allow for crappy file names containing spaces and minues?

 

ErikLund_Jensen
Rhodochrosite | Level 12

Hi @gsmith 

 

The problem is caused by the macro variable datetimef. You use a date-format on a datetime-value, so you ask SAS to take the number of seconds since 10 jan 1960 - right now it is 1875696783, and use it as the number of days. The largest date value in SAS is 2936547, so your value is larger than the max. date, and the formatted value becomes  a string of stars instead of a formatted date.

 

Have a look at these 3 examples. Only the last gives a valid filename:

 

192  %let datetimef=%sysfunc(datetime(),yymmddd10.);
193  %put &=datetimef;
DATETIMEF=**********
194
195  %let datetimef=%sysfunc(datetime(),datetime22.0);
196  %put &=datetimef;
DATETIMEF=09JUN2019:10:56:57
197
198  %let datetimef=%sysfunc(date(),yymmddd10.);
199  %put &=datetimef;
DATETIMEF=2019-06-09

By the way - You don't get the filename you expect, because the dot disappears. It is taken as a terminator for the macro variable, so you don't get the filetype separated from the file name. You need 2 dots:

 

201  data _null_;
202      a =  "c:\temp\FDTTEST_&datetimef.upd";
203      put a;
204
205      a =  "c:\temp\FDTTEST_&datetimef..upd";
206      put a;
207  run;

c:\temp\FDTTEST_2019-06-09upd
c:\temp\FDTTEST_2019-06-09.up

 

gsmith
Obsidian | Level 7

Sorry I didn't get this in and tested quicker, but I had jury duty.

 

Your solution worked perfectly.

 

Here's the file name that was created, which is exactly what I was looking for.

 

FDTTEST_2019-06-12.upd

 

 

Thanks,

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1160 views
  • 0 likes
  • 3 in conversation