BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8


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

1 ACCEPTED SOLUTION

Accepted Solutions
Anotherdream
Quartz | Level 8

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

View solution in original post

3 REPLIES 3
Anotherdream
Quartz | Level 8

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

robertrao
Quartz | Level 8

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

Regards

sascom10
Calcite | Level 5

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;

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 898 views
  • 3 likes
  • 3 in conversation