## PROC SORT

Solved
Super Contributor
Posts: 1,041

# PROC SORT

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

Accepted Solutions
Solution
‎05-20-2013 01:19 PM
Super Contributor
Posts: 418

## Re: PROC SORT

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

All Replies
Solution
‎05-20-2013 01:19 PM
Super Contributor
Posts: 418

## Re: PROC SORT

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

Super Contributor
Posts: 1,041

## Re: PROC SORT

Yes I will have to do a SET By ID and PREFIXin the succeding step immediately after SORTING

Regards

Occasional Contributor
Posts: 15

## Re: PROC SORT

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;

🔒 This topic is solved and locked.