0

I am having trouble reading in one particular column of data. The raw text file column I am having trouble with looks like this:

55.49
1:23.57
32.22
5:38.43
12:52.17
25.13

The form is minute minute : second second ms ms. this particular data does not go into the hours. I tried formatting the variable as TIME6.2; but I am getting missing values for over 70% of the data. I also messed around with adjusting the width. I also tried using the informat mmss but I did not have any success. However I may be using it incorrectly. As of now, I am reading the data in as a character value but I need it to be a numeric value so I can do data comparisons.

Any advice would be greatly appreciated!

Thanks!

EDIT: I wanted to make a note that these are elapsed times(race results). I hope to read the data in and then be able to compare the race times as to rank 1st,2nd,3rd place etc.

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
Jax
  • 27
  • 6

1 Answers1

0

First thing you need to understand is the difference between informats and formats.

Informat is a pattern that SAS uses to convert text into a number. The informat you want to use is hhmmss..

The format is something that is applied to a number; it tells SAS how you want a particular number to be displayed or printed. In order to represent your times, you need a width greater than 6 to account for the : and . characters you want printed. Try something larger like time12.2 format. Total width of 12, with two spaces for the ms digits:

EDIT: Assuming your text file is delimited, it seems the hhmmss informat doesn't like values that are not wide enough. It does work if you read the time in as character $ then use the input() function to convert the times to numbers.

data yourdata;
  format finaltime time12.2;
  infile cards dlm=',';
  input age team finaltimec $ score;
  finaltime = input(finaltimec,?? hhmmss.);
  drop finaltimec;
  cards;
20,1,55.49,1
22,1,1:23.57,2
34,1,NA,3
19,2,32.22,4
55,3,5:38.43,5
17,3,12:52.17,6
31,3,25.13,7
;
run;
DWal
  • 2,752
  • 10
  • 19
  • thank you. I tried to use the format and the informat and I still do not return values for the times that are over a minute. I now notice another issue with my read... Some values show up as 'NA'. I also should note that these are elapsed times for a race, not a standard time of day. In the end I hope to read these race times into my data step and then compare the results (eg who was the fastest etc).. – Jax Feb 22 '15 at 18:51
  • Just add `??` after your variable in the `input` statement to avoid errors when you hit "NA". I can't tell you why your code doesn't work unless you post it. The data step I posted above does work. – DWal Feb 22 '15 at 19:34
  • Once again I appreciate the time your taking to help me- – Jax Feb 22 '15 at 19:39
  • my code looks exactly like this: format FinalTime time12.2; input Age Team FinalTime ?? hhmmss. Score; All that is returned to me are missing values. – Jax Feb 22 '15 at 19:46
  • I see that it is not working with a delimited file. The hhmmss informat is relatively new, and I might be misunderstanding how it works, but it doesn't really make sense to me how it is working. Try this instead: read the value in as a character, then use the `input` function to change it to a time. See the edited answer above. – DWal Feb 22 '15 at 21:22