Could you provide more information? Is the variable that contains 0900 and 0930 numeric or character? (I'm guessing character)
Does 0900 represent 9 minutes and zero seconds, or is it 9 hours and 0 minutes?
Numeric variables don't have leading zeros unless they are formatted. Can you please run PROC CONTENTS and confirm this variable is numeric, and tell us what the format is?
You didn't answer my other question:
"Does 0900 represent 9 minutes and zero seconds, or is it 9 hours and 0 minutes?"
@Sowmya12 wrote:
Hii
Id time$
1 0900
2 0930
3 0825
The time variable is in character and the output should be in time5.
Format.
Thanks
Sowmya
Untested:
data want;
set have;
length time 8 helper $ 5;
format time time5.;
helper = cats(substr(timeStr, 1, 2), ':', substr(timeStr, 3, 2));
time = input(helper, time.);
run;
What do you have now? Is that "0900" a character value? A number? What is the name of the variable?
If character you create a new variable that holds a SAS time value and assign a format: One way:
data example; x='0900'; numval = input(x,f4.); timevalue = hms(int(numval/100), mod(numval,100),0); format timevalue time5.; run;
The function hms needs a numeric hour, minute and second value. Since you don't have any seconds shown then that uses 0.
If your current variable is numeric then skip the step that creates Numval.
The format shows values in HH:MM format.
You could drop Numval from the data.
If your variable is a number you could use the name in both the places numval appears in the HMS function and the Timevalue variable.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: