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

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3066 views
  • 0 likes
  • 3 in conversation