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.
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!
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.