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
SAS Super FREQ
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 696 views
  • 0 likes
  • 2 in conversation