Update date and time

Reply
Frequent Contributor
Posts: 85

Update date and time

Hi,

want to update the date and time for transaction data

eg.,

data base;

input id name$;

datlines;

11 abc

14 bwr

13 zys

;

run;

i am adding date column to it

data master;

set base;

date=today();

format date datetime16.;

run;

i have a transaction table

data transaction;

input id name$;

datalines;

11 xya

12 bcd

13 ars

;

run;

i want to update transaction table to master if first two columns update then date and time should also update

else date and time  remain same

can any one help

Super User
Super User
Posts: 6,499

Re: Update date and time

First use DATETIME() function if you want to get the current time as a datetime variable.  The TODAY() function just gives the date.

What do you mean by "if first two columns update"?

Classic SAS program would be:

data base;

merge base transaction (in=intran);

by id name;

if intran then datetime=datetime();

run;

This program does not care if the values of the KEY variables in the transaction file are different than the values in the old file. The time stamp is updated just because the record was in the transaction file. Records that don't need updating would not normally be included in the transaction file.

IF you really want to update the old table in place instead of the more normal SAS process of recreating the whole dataset then you will need a little more sophisticated program.

Super Contributor
Posts: 349

Re: Update date and time

Hi Santosh,

Try this..Hope this is what you want as output..

data master;

set base;

date=datetime();

format date datetime16.;

run;

data transaction;

input id name$;

date=datetime();

format date datetime16.;

datalines;

11 xya

12 bcd

13 ars

;

run;

proc sort data=base;by id ;run;

proc sort data=transaction;by id ;run;

DATA master;

   MODIFY master  transaction;

   BY id ;

   IF _IORC_ = %SYSRC(_SOK) THEN REPLACE;

RUN;

Thanks,

Shiva

Ask a Question
Discussion stats
  • 2 replies
  • 443 views
  • 0 likes
  • 3 in conversation