BookmarkSubscribeRSS Feed
teja5959
Fluorite | Level 6

Data have character time 

time

10:32

10:14

10:15

10:06

09:42

 

i want 

10:32:00

10:14:00

10:15:00

10:06:00

09:42:00

4 REPLIES 4
mkeintz
PROC Star

You would read a raw file (i.e. a text file with character values for time) with an INPUT statement, and a suitable INFORMAT for the variable.  Analogously you can read a character variable to a numeric (time) variables with an INPUT function, and a suitable INFORMAT.

 

data have;
  input txt_time $5.;
datalines;
10:32
10:14
10:15
10:06
09:42
run;

data want;
  set have;
  num_time=input(txt_time,time5.0);
  format num_time time8.0;
  put num_time=;
run;

whilch display on the log

num_time=10:32:00
num_time=10:14:00
num_time=10:15:00
num_time=10:06:00
num_time=9:42:00
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
DrAbhijeetSafai
Pyrite | Level 9
Found it helpful!
Dr. Abhijeet Safai
Associate Data Analyst
Actu-Real
novinosrin
Tourmaline | Level 20
data have;
input time $10.;
cards;
10:32
10:14
10:15
10:06
09:42
;

data want;
set have;
num_time=input(time,time.);
format num_time time8.;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 8742 views
  • 1 like
  • 5 in conversation