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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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