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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1318 views
  • 0 likes
  • 2 in conversation