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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1016 views
  • 1 like
  • 3 in conversation