BookmarkSubscribeRSS Feed
XMonsterX
Obsidian | Level 7

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

4 REPLIES 4
ballardw
Super User

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.));
FreelanceReinh
Jade | Level 19

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

XMonsterX
Obsidian | Level 7

This worked 🙂 unfortunately no period separating the numbers but still works! Thanks a million from all the way over in North America! 😄

FreelanceReinh
Jade | Level 19

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;

 

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
  • 4 replies
  • 7505 views
  • 3 likes
  • 3 in conversation