I have a data set with two date variables, FROM_DTTM and TO_DTTM. There's four rows. For the first three rows, I need to make TO_DTTM be equal to FROM_DTTM plus one second. The fourth row should remain unchanged.
Can someone please suggest what kind of code to use for this? I know I can use FIRST. and LAST. to identify the first and last rows, but I don't know about the second and third. Perhaps a while-loop with a count would be best? Alas I remain a bit inexperienced about programming. Please be specific if you can.
Thanks for your time.
For your very specific case, assuming that you have only 4 rows in the table and assuming that to_dttm and from_dttm contain SAS datetime values:
data ...
set ...
if _n_<=3 then TO_DTTM=FROM_DTTM+1;
...
run;
This looks very much like something related to SCD2. If so then TO_DTTM should actually be 1 second less than FROM_DTTM of the NEXT record (and not within the same record).
Is this about aligning records which got loaded using type 2 loading techniques. Is so let us know and if possible also post your data as the alignment needs then to be done a bit different as shown in the pseudo code I've posted.
For your very specific case, assuming that you have only 4 rows in the table and assuming that to_dttm and from_dttm contain SAS datetime values:
data ...
set ...
if _n_<=3 then TO_DTTM=FROM_DTTM+1;
...
run;
This looks very much like something related to SCD2. If so then TO_DTTM should actually be 1 second less than FROM_DTTM of the NEXT record (and not within the same record).
Is this about aligning records which got loaded using type 2 loading techniques. Is so let us know and if possible also post your data as the alignment needs then to be done a bit different as shown in the pseudo code I've posted.
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.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.