Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing Time Values

Status
Not open for further replies.

shelby55

Technical User
Jun 27, 2003
1,229
CA
Hello

I have a flat file that I am trying to import. The time field is in a column separate from the date and doesn't have any colons i.e. 1040, 1230 etc.

What is the input statement for importing these?

Note also that the field has some "9999" values indicating time not available - how can I import these as zero?

Thanks.

Shelby
 
There are a number of things you have to keep in mind when dealing in time values.
First off, what type of time value are you going to be dealing with (12 hour or 24 hour)
Second, you must remember that SAS stores time values as the number of seconds from midnight. So a time value of 9999 should not be zero but set to 'missing' or ('.'). (a time of 0 is actually midnight)

There must be an easier way than I will describe below, but this works great.

First make a picture format so that all of your time value get the 'colon'.
Code:
proc format;
  picture tmval
   01-9999=99:99; 
quit;

Then you can use a combination of the put and input functions to get the desired SAS time for the value that you 'read' in.

Code:
data _null_;
  x=1040;
  y=input(put(x,tmval.), time5.);
put x= y=;
run;

Of course this is an example and you should have a real dataset name as well as whatever infile etc. statement that you would use.

Hope this helps you.
Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top