Hi all,
I've calculated a time difference between two datetime variables in a dataset. When I try to export it Excel, the format of the time difference are incorrect and inconsistent. I'd like them to be output in HH:MM format.
The code I'm using is as follows:
data time_diffs;
set times;
diff = t1 - t2;
/* format diff hhmm. */
run;
proc means;
class by_var;
var diff;
output out=median_diffs median(diff)=diff;
run;
data diffs_output;
set median_diffs
diff_text = put(diff, hhmm.);
run;
I'm using Enterprise guide and export with the export button in the Output Data tab to an xlsx.
In the xlsx some values are just text as expected, but some have the time as a number.
Can anyone help?
You need to explain more what you mean by "button in the Output Data tab".
First how are you running your SAS code? Sounds like you are using some type of point and click interface. Which one? Enterprise Guide? SAS/Studio? Something else?
Show an example of what is wrong. It is not clear what variable you are talking about. You don't show a variable named TIME.
Your code generates dataset TIME_DIFFS, MEDIAN_DIFFS and DIFF_OUTPUT. Which of these are you exporting?
Your code mentions variables named T1, T2, DIFF, BY_VAR, and DIFF_TEXT. Which of these are showing properly? Which are not?
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 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: