hello,
i have two variables in my data set date and time(HH:MM) in seperate columns, i need to combine those columns and sort the data by date and time per subject.
While doing so i came across the situation like, the time is missing for one of the subjects ,and when i sort the data ,the record with missing time sorted to the top which leads to incorrect sorted data.
Kindly help me with this and handle the situation
Thank you
Here is one solution
UNTESTED CODE
data want;
set have;
if not missing(time) then datetime=dhms(date,hour(time),minute(time),0);
else datetime=dhms(date,0,0,0);
run;
proc sort data=have;
by datetime;
run;
Naturally, there are other solutions regarding what to do with the missing time variable, I'm sure you can think of other ways to handle this.
Here is one solution
UNTESTED CODE
data want;
set have;
if not missing(time) then datetime=dhms(date,hour(time),minute(time),0);
else datetime=dhms(date,0,0,0);
run;
proc sort data=have;
by datetime;
run;
Naturally, there are other solutions regarding what to do with the missing time variable, I'm sure you can think of other ways to handle this.
thank you so much paige
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.