BookmarkSubscribeRSS Feed
HelenJ
Calcite | Level 5
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
1 REPLY 1
Cynthia_sas
Diamond | Level 26
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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1 reply
  • 933 views
  • 0 likes
  • 2 in conversation