BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NevermoreRedres
Obsidian | Level 7

Hello Everyone! Hope you all are doing great!

I got some time variables in the hh:mm:ss format and i need to get the mean of them:

04:47:32 02:26:01 02:22:59 02:33:03 01:57:31
04:40:54 03:27:40 01:43:49 02:46:13 01:20:01
04:36:07 03:36:04 01:28:21 02:27:37 01:18:16
04:07:07 03:55:09 01:51:59 02:21:11 01:05:33
03:55:44 04:38:44 01:17:46 02:16:04 00:57:53
03:59:19 05:00:16 01:13:54 02:39:59 00:59:44

 

I need to get the mean by colunm, so for example, i want SAS to read

04:47:32
04:40:54
04:36:07
04:07:07
03:55:44
03:59:19

add up the time in the colunm (26:06:43) and divide it by the number of lines (6). How to i program this? 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

First, these have to be numeric time values, not character strings or numeric dates or anything else. Assuming that's what they are, PROC MEANS/PROC SUMMARY will compute the means for you.

 

proc summary data=have;
    var column1-column5;
    output out=want mean=;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

First, these have to be numeric time values, not character strings or numeric dates or anything else. Assuming that's what they are, PROC MEANS/PROC SUMMARY will compute the means for you.

 

proc summary data=have;
    var column1-column5;
    output out=want mean=;
run;
--
Paige Miller
NevermoreRedres
Obsidian | Level 7

Hey PaigeMiller! Thanks for the help!

Sorry if the question was to basic.

 

Here the final output if anyone needs an example:

DATA have;
infile cards dlm='09'x dsd truncover;
input (column1 column2 column3 column4 column5) (:time.);
format column1--column5 time8.;
CARDS;
04:47:32	02:26:01	02:22:59	02:33:03	01:57:31
04:40:54	03:27:40	01:43:49	02:46:13	01:20:01
04:36:07	03:36:04	01:28:21	02:27:37	01:18:16
04:07:07	03:55:09	01:51:59	02:21:11	01:05:33
03:55:44	04:38:44	01:17:46	02:16:04	00:57:53
03:59:19	05:00:16	01:13:54	02:39:59	00:59:44
run;

proc summary data=have;
    var column1-column5;
    output out=want mean=;
run;

Thanks again, PaigeMiller!

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
  • 2 replies
  • 921 views
  • 1 like
  • 2 in conversation