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

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. Smiley Happy

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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.

View solution in original post

1 REPLY 1
Patrick
Opal | Level 21

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 1 reply
  • 613 views
  • 0 likes
  • 2 in conversation