04-19-2016 01:05 PM
What format does SAS show the variable as having? If the format is currently hhmm5 then the value is an actual SAS time value and you can change the format for display.
But convert to what? There are a number of options. If you only want the hour displayed and no decimal portion then use HHMM2. or HOUR2.
In a procedure that would be :
Proc print data=have;
format time hour2.;
Or you can change the format permanently in a variety of methods.
04-19-2016 01:07 PM
So when I tried that proc print command, it says my arrtime variable is in a character format:
4804 Proc print ;
4805 var arrtime;
4806 format arrtime hour2.;
ERROR: You are trying to use the numeric format HOUR with the character variable arrtime in data set IAT.TIMETOIAT2.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.03 seconds
cpu time 0.01 seconds
04-19-2016 03:46 PM
The you data did not have the format you stated, it had a $xx. format.
Proc Contents data= datasetname; run;
will tell the type and format of variables.
Note that FORMAT has a very specific meaning when using SAS. FORMAT refers to how a value is displayed.
Since you don't say how you read the data into SAS we can't address that but it is a very good idea to learn how to read dates and times into SAS date, time or datetime valued variables due to the number tools designed to work with them.
So the question could become: Are you trying to create a TIME valued variable, a character variable that has the hour from your chracter string of hh:mm:ss or create a numeric variable that has the number in the first position.
In a data step:
SAStimevar = input(arrtime,hhmmss.);
Format SASTimeVar hhmmss.;
CharacterHour = scan(arrtime,1,':');
Numerichour = input(scan(arrtime,1,':'),best2.);
Shows some ways to make one of each type of variable.