HI Im having and issue with a time column.
the column is a time9. 14:04:00
WHat i need to pull is the hour segment 14
when I did is a data step
data report;
set report;
hour= substr( left( time) ,2,4);
it gives the sas date of 50640. This is what it pulls in 0640 But the col I'm refer looks like this 14:04:00
thanks for your assistance
It must be that variable hour is already declared as a character variable prior to the hour=hour(time) statement. Look at SAS log, there must be a statement such as:
NOTE: Numeric values have been converted to character
values at the places given by: (Line):(Column).
Try the following test:
data report;
length hourText $8; /* Declare hourText as a character variable */
time = '14:30:00't; /* time is a true SAS time value */
hourText = hour(time); /* Implies a conversion to character */
hourNumber = hour(time); /* Number result is assigned to a numeric variable (by default) */
run;
proc print; run;
If you want to get a number, assign the result of hour(time) to a variable that hasn't been declared as a character variable.
PG
If your time variable is a true SAS time value, you should use hour = hour(time) to get the hour number or hour=put(hour(time),best.) to get the character representation.
If time is a character representation of time then you should use hour = scan(time,1,":") . - PG
HI PGStats,
the hour did work it gave me the hour. But it converted it to a character for example
14:04:00 it gave me a 14 as a character what can i do within the datastep to make it a number? THANKS
data report;
set report;
hour=hour(time):
run;
It must be that variable hour is already declared as a character variable prior to the hour=hour(time) statement. Look at SAS log, there must be a statement such as:
NOTE: Numeric values have been converted to character
values at the places given by: (Line):(Column).
Try the following test:
data report;
length hourText $8; /* Declare hourText as a character variable */
time = '14:30:00't; /* time is a true SAS time value */
hourText = hour(time); /* Implies a conversion to character */
hourNumber = hour(time); /* Number result is assigned to a numeric variable (by default) */
run;
proc print; run;
If you want to get a number, assign the result of hour(time) to a variable that hasn't been declared as a character variable.
PG
hi
if for some reason the variable is in a character format you can allways create a new variable and converet it to a numeric format using input .
for example :
data report;
set report;
hour=hour(time);
hour1=input(hour,12.);
run;
good luck
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: