1
1

Hi All

What's the best way to read in a time from a text file that's in an HHMM format?

data test;
  attrib time format=time.;

  input time ;

  put time=;

/* EXAMPLE IS FOR 2:59 PM */
datalines;
  1459   
;
run;

time=0:24:19

Thanks Rob

asked 21 Mar '11, 16:46

Robert%20Penridge's gravatar image

Robert Penridge ♦
911724
accept rate: 36%


In SAS 9.2 you can use the B8601TMw.d informat.

data test;
  attrib time informat=b8601tm8. format=time.;
  input time ;
  put time=;
datalines;
1459
;
run;

time=14:59:00
link

answered 22 Mar '11, 07:25

Laurent%20de%20Walick's gravatar image

Laurent de W...
1814
accept rate: 100%

Rob,

Found this which seems to do the job. Custom informat.

data cntlin (drop = i j) ;
  retain fmtname "hhmm" type "I" ;
  do i = 0 to 23 ;
     do j = 0 to 59 ;
        start = put(i,z2.)||put(j,z2.) ;
        label = input(put(i,z2.)||":"||put(j,z2.),time5.) ;
        output ;
     end ;
  end ;
run ;

proc format cntlin=cntlin;quit;

data test;
  attrib time format=time.;

  input time hhmm. ;

  put time=;

/* EXAMPLE IS FOR 2:59 PM */
datalines;
1459
;
run;

time=14:59:00
link

answered 21 Mar '11, 21:43

richie's gravatar image

richie
962
accept rate: 33%

Nice one Richie... Handy code to know... Where are you working these days? Aus? London? Singapore? I'm in Vegas now =)

(22 Mar '11, 15:48) Robert Penridge ♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×3
×2
×1

Asked: 21 Mar '11, 16:46

Seen: 1,733 times

Last updated: 22 Mar '11, 07:25

powered by OSQA