BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

View solution in original post

4 REPLIES 4
stat_sas
Ammonite | Level 13

data have;

dt=date();

tm=time();

format dt date9.;

format tm time.;

run;

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

thanks stat

Tom
Super User Tom
Super User

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

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

sweet!

thanks Tom

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

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
  • 37485 views
  • 5 likes
  • 3 in conversation