BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Lapis Lazuli | Level 10

Hi guys, 

suppose to have the following: 

data have;
  input ID :$20. Admission :date09. Discharge :date09. Variable1 Variable2; 
  format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 1  0 
0001 21FEB2015 31DEC2015  .  . 
0001 21FEB2015 31DEC2015 0  1 
; 

Is there a way to swap rows with missing values to have the following?

Rows with missing values are present only when there are identical and replicated rows.

 

data have1;
  input ID :$20. Admission :date09. Discharge :date09. Variable1 Variable2; 
  format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 1  0 
0001 21FEB2015 31DEC2015 0  1
0001 21FEB2015 31DEC2015  .  .  
; 

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
antonbcristina
SAS Super FREQ

Hi @NewUsrStat, a simple sort will work here, making sure to sort by all columns and descending values for variable1/2:

 

proc sort data=have out=want;
	by id admission discharge descending variable1 descending variable2;
run;

 

View solution in original post

2 REPLIES 2
antonbcristina
SAS Super FREQ

Hi @NewUsrStat, a simple sort will work here, making sure to sort by all columns and descending values for variable1/2:

 

proc sort data=have out=want;
	by id admission discharge descending variable1 descending variable2;
run;

 

PaigeMiller
Diamond | Level 26

Given this trivial example, is it safe to assume that sorting always solves the problem? Could there be cases where sorting does not solve the problem?

--
Paige Miller