SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
teja5959
Obsidian | Level 7

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
Lapis Lazuli | Level 10
Found it helpful!
Dr. Abhijeet Safai
Certified Base and Clinical SAS Programmer
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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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