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

I would  like to use the export procedure in order to create an excel with a time stamp, but proc export does not like the :.

So I define the global variable

%let zeitstempel = %SYSFUNC(DATE(), DDMMYYP10._at_%SYSFUNC(TIME(),TIME5.);

%put &zeitstempel.;

This works fine.

Now I try to replace the : by _

%let zs = %SYSFUNC(tranwrd(&zeitstempel.),":","_");

%put &zs.;

                    

This gets ignored by sas.

Do I need to add quotation marks and get rid of them later?

Is there another way to achiveIs this?

Is there maybe another time format that I can set in order to avoid my problem?

Thanks

Gregor


1 ACCEPTED SOLUTION

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

Hi,

I would recommend against having dates/times in filenames.  For two reasons, time/date is not an easy thing to work with, and version control systems generally need the filename to stay the same. 

If you continue though, the below will switch : for _:

data _null_;

  call symput('DT',cats(put(date(),ddmmyyp10.),"_at_",tranwrd(put(time(),time5.),":","_")));

run;

%put &DT.;

Personally I wouldn't try to do this in %let statements.  If you have to deal with parameters then put them in a datastep and call symput/execute the required output.

View solution in original post

10 REPLIES 10
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

I would recommend against having dates/times in filenames.  For two reasons, time/date is not an easy thing to work with, and version control systems generally need the filename to stay the same. 

If you continue though, the below will switch : for _:

data _null_;

  call symput('DT',cats(put(date(),ddmmyyp10.),"_at_",tranwrd(put(time(),time5.),":","_")));

run;

%put &DT.;

Personally I wouldn't try to do this in %let statements.  If you have to deal with parameters then put them in a datastep and call symput/execute the required output.

Gregor
Obsidian | Level 7

This works perfectly.  I need to export excels with time stamps for documentary reasons. The numbers I calculate here have an impact on the data I deliver to an external recipant.

Thanks a bunch.


Tom
Super User Tom
Super User

The problem is the quotes. In macro code everything is a character strings so you do not need to put quotes around strings to distinguish them from numbers or variable names.

%let zs = %SYSFUNC(tranwrd(&zeitstempel.),:,_));

Message was edited by: Tom Abernathy Fixed missing right parenthesis.

Gregor
Obsidian | Level 7

This leads to ERROR: Expect close parenthesis after macro function not found.

Thanks a lot, anyway.


Tom
Super User Tom
Super User

Add the extra ) required because TRANWRD() function is wrapped inside of %SYSFUNC() call.

Ksharp
Super User

customize  date format , you can get any form of date.

proc format;

picture fmt

low-high='%0d.%0m.%Y_at_%0H_%0M' (datatype=datetime);

run;

%let zeitstempel = %SYSFUNC(DATETIME(), fmt.);

%put &zeitstempel.;

Xia Keshan

Ksharp
Super User

customize  date format , you can get any form of date.

proc format;

picture fmt

low-high='%0d.%0m.%Y_at_%0H_%0M' (datatype=datetime);

run;

%let zeitstempel = %SYSFUNC(DATETIME(), fmt.);

%put &zeitstempel.;

Xia Keshan

BOBSAS
Calcite | Level 5

/*The above step won't work becoz you didnt mask the quotes..So see below*/

%let zs = %SYSFUNC(tranwrd(&zeitstempel.,%str(:),%str(_)));

%put &zs.; 

Tom
Super User Tom
Super User

The problem is not that the quotes are not masked, but that the quotes are included in the string to find and so there is no match.

Also note that neither : or _ are macro triggers so there is no need to use %STR() to quote them.

BOBSAS
Calcite | Level 5

Yeah. Exactly... Thanks Tom.

Simply we can write as below,

%let zs = %SYSFUNC(tranwrd(&zeitstempel.:,_));

%put &zs.;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 10 replies
  • 1457 views
  • 8 likes
  • 5 in conversation