BookmarkSubscribeRSS Feed
RoddyJ
Obsidian | Level 7

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? 

3 REPLIES 3
Tom
Super User Tom
Super User

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?

RoddyJ
Obsidian | Level 7
Enterprise guide, will update post
Tom
Super User Tom
Super User

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?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 504 views
  • 1 like
  • 2 in conversation