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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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