Time management and B- work for stats programming work

Hello! I’m trying to figure out how I can reconcile 2 concepts: my statistical computer programming work that “takes as long as it takes”, and then “B- work/getting work done in the time I allot for it”. How can I plan for time when to comes to computer programming/statistical analysis work? When I get a new set of data, I don’t know if it will take 2 hours or 8 hours to clean up. It depends on how many errors, duplicates, etc. are in the file. So I can plan for 2 hours, but I can’t just “be done” with B- work because the program script literally won’t run until the data is in A+ shape and all errors in the data are corrected. Maybe always schedule 8 hours for it so I can always deliver it? And then if it takes only 2 hours, I move on to the next task on my calendar? Ha – I think I just figured out a solution, but will also gratefully take any tips you have!