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;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.