hi guys,
as a header record i need to have the current date and time (hh:mm:ss) but no clue how to do it. I know macros will do the job but any other way than it would be appreciated
DATA _NULL_;
FILE 'C.......txt';
IF _n_=1 THEN DO;
PUT current date current time;
END;
SET mylib.cars nobs=numobs end=last ;
put _ALL_;
IF last THEN DO;
PUT 'THIS IS MY TRAILER RECORD';
END; run;
The &SYSDATE9 and &SYSTIME automatic macro variables will have the date and time that the SAS session started. You could also call the DATE() and TIME() functions or the DATETIME() function to get current time. You can do that in macro language using %SYSFUNC().
data _null_;
*file 'c.......txt';
if _n_=1 then do;
put "HEADER: %sysfunc(date(),date9.) %sysfunc(time(),tod8.)" ;
end;
if eof then do;
put 'TRAILER: ' nobs=;
end;
set sashelp.class nobs=nobs end=eof ;
put (_all_) (:);
run;
HEADER: 17SEP2014 01:16:01
Alfred M 14 69 112.5
Alice F 13 56.5 84
Barbara F 13 65.3 98
Carol F 14 62.8 102.5
Henry M 14 63.5 102.5
James M 12 57.3 83
Jane F 12 59.8 84.5
Janet F 15 62.5 112.5
Jeffrey M 13 62.5 84
John M 12 59 99.5
Joyce F 11 51.3 50.5
Judy F 14 64.3 90
Louise F 12 56.3 77
Mary F 15 66.5 112
Philip M 16 72 150
Robert M 12 64.8 128
Ronald M 15 67 133
Thomas M 11 57.5 85
William M 15 66.5 112
TRAILER: nobs=19
data have;
dt=date();
tm=time();
format dt date9.;
format tm time.;
run;
thanks stat
The &SYSDATE9 and &SYSTIME automatic macro variables will have the date and time that the SAS session started. You could also call the DATE() and TIME() functions or the DATETIME() function to get current time. You can do that in macro language using %SYSFUNC().
data _null_;
*file 'c.......txt';
if _n_=1 then do;
put "HEADER: %sysfunc(date(),date9.) %sysfunc(time(),tod8.)" ;
end;
if eof then do;
put 'TRAILER: ' nobs=;
end;
set sashelp.class nobs=nobs end=eof ;
put (_all_) (:);
run;
HEADER: 17SEP2014 01:16:01
Alfred M 14 69 112.5
Alice F 13 56.5 84
Barbara F 13 65.3 98
Carol F 14 62.8 102.5
Henry M 14 63.5 102.5
James M 12 57.3 83
Jane F 12 59.8 84.5
Janet F 15 62.5 112.5
Jeffrey M 13 62.5 84
John M 12 59 99.5
Joyce F 11 51.3 50.5
Judy F 14 64.3 90
Louise F 12 56.3 77
Mary F 15 66.5 112
Philip M 16 72 150
Robert M 12 64.8 128
Ronald M 15 67 133
Thomas M 11 57.5 85
William M 15 66.5 112
TRAILER: nobs=19
sweet!
thanks Tom
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.