Hi,
So I'm pretty stuck here, it seems like there should be an answer but I can't seem to find one.
I need to do a %LET NOW1 = %SYSFUNC(TIME(),); for HHMMSSAMPM or HHMMAMPM. I would very much prefer if it could be a 12 hour clock, not 24. It can have a " . " or " - " instead of " : ". It needs to be those because I'm taking a file, copying, pasting (into a new folder), renaming the new file (.csv) and deleting the old file. I need it to be 01-08-2016_thenameofmyfile_513pm(today's date, which I'm using a sysfunc(date(),) for). I really don't care if it's 5.13pm or whatever but it's excel so I cant have a colon in the title.
Filename in "D:\&NOW2._&NOW3.&NOW1..csv";
Filename out "D:\&NOW2._&NOW3.&NOW1..csv";
Filename ferase pipe "D:\&NOW2._&NOW3.&NOW1..csv";
Filename ren pipe "D:\&NOW2._&NOW3.&NOW1..csv";
DATA REN;
INFILE REN PAD;
INPUT OLD $250. ;
NEW=TRANWRD(OLD,'12-10-2015',("&NOW2._&NOW1.&NOW3."));
RUN;
/*To rename them all*/
DATA _NULL_;
SET REN;
RC=RENAME(OLD, NEW, 'FILE');
PUT RC;
RUN;
/* Copy file/Paste file */
DATA _NULL_;
LENGTH FILEIN 8 FILEID 8;
FILEIN = FOPEN('in','I',1,'B');
FILEID = FOPEN('out','O',1,'B');
REC = '20'x;
DO WHILE(FREAD(FILEIN)=0);
RC = FGET(FILEIN,REC,1);
RC = FPUT(FILEID, REC);
RC =FWRITE(FILEID);
END;
RC = FCLOSE(FILEIN);
RC = FCLOSE(FILEID);
RUN;
FILENAME IN CLEAR;
FILENAME OUT CLEAR;
/* Delete Old file */
DATA _NULL_ ;
rc = FDELETE ('FErase') ;
RUN ;
FILENAME FErase CLEAR ;
This is more or less what I'm doing, though the filename's aren't correct, just put them to show what I'm up to, and theres 700 lines in between. So ya, what I need is a way I can get a time in there that has atleast hour,minute,and am/pm that doesn't have a period in there. If theres a better way of doing this I'm open to it but it's part of an automated program that basically runs 24 hours a day so it needs to have an original name everytime it saves the file.
Thanks,
Monster
I think You want a custom time format
proc format library=work;
picture mytime
low - high = '%I-%M%p'(datatype=time)
;
run;
/* and use */
%let Now1 = %sysfunc(putn(%sysfunc(time()),mytime.));
Maybe this can be a start:
%let now1=%sysfunc(compress(%sysfunc(TIME(),timeampm11.),%str( :)));
%put &now1;
The result, however, tells me that it has become fairly late here in Central Europe, so I have to call it a day. Sorry. 🙂
This worked 🙂 unfortunately no period separating the numbers but still works! Thanks a million from all the way over in North America! 😄
You're welcome.
Periods are no problem either:
%let now1=%sysfunc(compress(%sysfunc(translate(%sysfunc(time(),timeampm11.),.,:))));
%put &now1;
Also, @ballardw's elegant approach can easily be modified to produce this same time format. In addition, his picture format can be extended (more easily than the above definition of NOW1) to pad one-digit hour values with a leading zero, which may be helpful for sorting purposes. Here's how:
proc format library=work;
picture mytime
low - high = '%0I.%M.%S%p'(datatype=time);
run;
%let now1 = %sysfunc(putn(%sysfunc(time()),mytime.));
%put &now1;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.