Hi ,
I have two datasets..
I want to set the two datasets first
and second do a :
proc sort data=have;
by ID DATE PREFIX;
run;
Problem:Missing takes the first position after sorting
Thanks
DATASET1
ID Date prefix
400 21OCT11:11:40:00 out
400 26OCT11:00:30:00 out
400 21OCT11:10:25:00 in
400 25OCT11:02:10:00 in
DATASET2
ID Date prefix
401 22FEB13:15:32:00 in
401 12MAR13:07:50:00 out
401 13MAR13:19:45:00 in
401 23APR13:08:08:00 out
401 26APR13:15:13:00 in
401 . out
WANT
400 21OCT11:10:25:00 in
400 21OCT11:11:40:00 out
400 25OCT11:02:10:00 in
400 26OCT11:00:30:00 out
401 22FEB13:15:32:00 in
401 12MAR13:07:50:00 out
401 13MAR13:19:45:00 in
401 23APR13:08:08:00 out
401 26APR13:15:13:00 in
401 . out
Your inherently chaning the way that sort works, and if you really need this (be careful with by grouping later!) then the way I usaully do this is to create a new variable that is equal to 0 when Date is Not missing, and Equal to 1 when date is missing..
Then, sort by the following order
proc sort data=have (drop=newvar);
by ID NEWVAR DATE PREFIX;
run;
Enjoy
Your inherently chaning the way that sort works, and if you really need this (be careful with by grouping later!) then the way I usaully do this is to create a new variable that is equal to 0 when Date is Not missing, and Equal to 1 when date is missing..
Then, sort by the following order
proc sort data=have (drop=newvar);
by ID NEWVAR DATE PREFIX;
run;
Enjoy
Yes I will have to do a SET By ID and PREFIXin the succeding step immediately after SORTING
Regards
data dat2 missing_dat;
set dataset2;
if date=. then output missing_dat;
else output dat2;
run;
data want;
set dataset1
dat2;
run;
proc sort data=want;
by ID DATE PREFIX;
run;
data want_final;
set want
missing_dat;
run;
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.