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
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.
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.
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.
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.
This leads to ERROR: Expect close parenthesis after macro function not found.
Thanks a lot, anyway.
Add the extra ) required because TRANWRD() function is wrapped inside of %SYSFUNC() call.
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
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
/*The above step won't work becoz you didnt mask the quotes..So see below*/
%let zs = %SYSFUNC(tranwrd(&zeitstempel.,%str(:),%str(_)));
%put &zs.;
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.
Yeah. Exactly... Thanks Tom.
Simply we can write as below,
%let zs = %SYSFUNC(tranwrd(&zeitstempel.:,_));
%put &zs.;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.