BookmarkSubscribeRSS Feed
programeerSAS
Fluorite | Level 6

Running this code :

 

data electric.blt_hours;
set electric.blt;

Hours = hour(TransDateTime) ;
run;

 

Here is the property of the datetime field that was read in using proc import with guessing rows option.

 

programeerSAS_0-1651226694071.png

 

Log states: 

 

NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 72:9
NOTE: There were 1 observations read from the data set ELECTRIC.BLT.
NOTE: The data set ELECTRIC.BLT_HOURS has 1 observations and 4 variables.
 
Not sure why the hour cannot be read if it is a numeric SAS date value it is reading from....

 

 

7 REPLIES 7
Kurt_Bremser
Super User

Your dataset has only one observation, and in this one observation the variable in question contains a missing value. From a missing value, only a missing value can result.

 


@programeerSAS wrote:

Running this code :

 

data electric.blt_hours;
set electric.blt;

Hours = hour(TransDateTime) ;
run;

 

Here is the property of the datetime field that was read in using proc import with guessing rows option.

 

programeerSAS_0-1651226694071.png

 

Log states: 

 

NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 72:9
NOTE: There were 1 observations read from the data set ELECTRIC.BLT.
NOTE: The data set ELECTRIC.BLT_HOURS has 1 observations and 4 variables.
 
Not sure why the hour cannot be read if it is a numeric SAS date value it is reading from....

 

 


 

Kurt_Bremser
Super User

PS from a valid datetime value, the HOUR function returns the hour as documented:

data _null_;
now = datetime();
hours = hour(now);
format now e8601dt19.;
put now= hours=;
run;

Log:

 69         data _null_;
 70         now = datetime();
 71         hours = hour(now);
 72         format now e8601dt19.;
 73         put now= hours=;
 74         run;
 
 now=2022-04-29T12:18:40 hours=12
programeerSAS
Fluorite | Level 6
Hi Kurt

My blt dataset has many rows of data in it.

This dataset also has just one month of data in it so ultimately I am trying to see when sales are made on each day broken down per hour, hence the first bit of code to extract the hour from the SAS datetime variable.
Sajid01
Meteorite | Level 14

Can you provide few rows of your data?

programeerSAS
Fluorite | Level 6

Hi Kurt - you were spot on! 

 

I had the table open but a piece of my code messed up the dataset. I re-imported, ran the code as is and voila! 

 

Thank you!

PaigeMiller
Diamond | Level 26

@programeerSAS 

Please provide the ENTIRE log for this DATA step, instead of what you did was just show us pieces of the log. Please copy the log as text and then click on the </> and paste the log into the window that appears.

Insert Log Icon in SAS Communities.png

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 7 replies
  • 1527 views
  • 0 likes
  • 4 in conversation