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_date | injury_time | injury_datetime |
14SEP2006 | 1:40:00 | 14SEP2006:01:40:00 |
29JUN2006 | 21:02:00 | . |
02AUG2006 | 16:31:00 | . |
02OCT2006 | 9:44:00 | 02OCT2006:09:44:00 |
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
Use TOD format:
input(cats(put(a.injury_date,date9.),put(a.injury_time,tod8.)),datetime17.) as injury_datetime format = datetime19.
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.
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
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.
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.