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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
pavan1
Obsidian | Level 7

thank you so much paige 

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 2 replies
  • 1410 views
  • 0 likes
  • 2 in conversation