DATA Step, Macro, Functions and more

sysdate and systime

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 444
Accepted Solution

sysdate and systime

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;


Accepted Solutions
Solution
‎09-17-2014 01:18 AM
Super User
Super User
Posts: 7,076

Re: sysdate and systime

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_) (Smiley Happy;

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

View solution in original post


All Replies
Trusted Advisor
Posts: 1,230

Re: sysdate and systime

data have;

dt=date();

tm=time();

format dt date9.;

format tm time.;

run;

Super Contributor
Super Contributor
Posts: 444

Re: sysdate and systime

thanks stat

Solution
‎09-17-2014 01:18 AM
Super User
Super User
Posts: 7,076

Re: sysdate and systime

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_) (Smiley Happy;

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

Super Contributor
Super Contributor
Posts: 444

Re: sysdate and systime

sweet!

thanks Tom

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 6864 views
  • 5 likes
  • 3 in conversation