SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Changing a date variable in three rows

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 90
Accepted Solution

Changing a date variable in three rows

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


Accepted Solutions
Solution
‎10-02-2012 05:05 AM
Respected Advisor
Posts: 4,173

Re: Changing a date variable in three rows

Posted in reply to EinarRoed

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


All Replies
Solution
‎10-02-2012 05:05 AM
Respected Advisor
Posts: 4,173

Re: Changing a date variable in three rows

Posted in reply to EinarRoed

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.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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