BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Scooter56
Calcite | Level 5

I have numeric date and time variables that I would like to combine into a single numeric datetime variable. The code below works on some of the data, but not all of it (more specifically it won't calculate a datetime for any row where the time variable has a two digit hour - see example output below Proc SQL code). The SAS log gives two notes: "Invalid year value" and "Invalid argument to function INPUT. Missing values may be generated." I have tried changing the datetime informat of the input statement but that doesn't help. Any suggestions on how to fix this using Proc SQL (I'm using SAS 9.2) would be appreciated.

 

proc sql ;
   select a.injury_date
	 ,a.injury_time
	 ,input(put(a.injury_date,date9.)||put(a.injury_time,time8.),datetime17.) as injury_datetime format = datetime19.
     from injury_data ;

 

injury_dateinjury_timeinjury_datetime
14SEP20061:40:0014SEP2006:01:40:00
29JUN200621:02:00.
02AUG200616:31:00.
02OCT20069:44:0002OCT2006:09:44:00
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If the variables are actual SAS date and Time valued then you can use

dhms(a.injury_date, 0,0,a.injury_time) as injury_datetime

 

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use TOD format:

input(cats(put(a.injury_date,date9.),put(a.injury_time,tod8.)),datetime17.) as injury_datetime format = datetime19.
Scooter56
Calcite | Level 5

Thanks! I copied your code directly from your post, but it didn't work. The new variable injury_datetime had a missing value for all data rows, and I got the same notes in the SAS log.

ballardw
Super User

If the variables are actual SAS date and Time valued then you can use

dhms(a.injury_date, 0,0,a.injury_time) as injury_datetime

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3 replies
  • 3731 views
  • 0 likes
  • 3 in conversation