DATA Step, Macro, Functions and more

Infile - problems converting time variable to SAS format

Reply
N/A
Posts: 1

Infile - problems converting time variable to SAS format

Hi!

I am trying to read an infile (semicolon separated file) with a time variable in the format hh:mm and I am only able to read it as a char variable.

Is it possible to tell SAS in the infile reading that this is a time variable and convert it to SAS format directly?

I tried to convert it after the variable list:

SASdate=input(VARNAME,hhmm.);

but it didn't work (as it is a char variable, I guess...).

Thankful for any help on this basic question! (Sorry for asking, I have tried to look it up on the online help but couldn't find anything helpful.)
/Helen
SAS Super FREQ
Posts: 8,862

Re: Infile - problems converting time variable to SAS format

Hi:
Try an "informat" -- a format to use when you read in the data -- on the INPUT statement (assuming you have an INPUT statement):
[pre]
** make some data;
data testdate;
infile datalines dlm=',';
input var1 $ datevar : mmddyy10.
timevar : time5.
var2 var3;
format datevar date7. timevar time5.;
datalines;
aaa,11/15/1950,19:35,101,202
bbb,11/15/1950,09:42,111,222
ccc,10/17/1991,14:45,333,444
ddd,11/29/1984,10:36,555,666
;
run;

options nodate nonumber nocenter;
ods listing;
** print data WITH assigned formats;
proc print data=testdate;
title '1) use assigned formats';
run;

** print data WITH diff formats to show values;
proc print data=testdate;
title '2) with diff formats display values';
format datevar mmddyy10. timevar time8.;
run;
[/pre]

If you already have a dataset, then the TIME. informat should work for your conversion:
[pre]
timevar = input(chartime,time5.);
[/pre]

cynthia
Ask a Question
Discussion stats
  • 1 reply
  • 124 views
  • 0 likes
  • 2 in conversation