BookmarkSubscribeRSS Feed
radhikaa4
Calcite | Level 5

Hello. I am trying to generate an algorithm that best catches the missing dates and replaces with the expected date if next consequent visit is completed. I would like to use PROC SQL, I am unable to 

 

Here is the sample dataset;

patientiddayvisit_dateexpected_visit_date
123430 1/30/2017
12341807/29/20177/29/2017
12343651/30/20181/30/2018
456730 1/20/2017
4567180 7/19/2017
45673651/19/20181/20/2018
789030 12/3/2016
78901806/1/20176/1/2017
7890365 12/3/2017

 

New dataset:

patientiddayvisit_dateexpected_visit_datenew_visit_date
123430 1/30/20171/30/2017
12341807/29/20177/29/20177/29/2017
12343651/30/20181/30/20181/30/2018
456730 1/20/20171/20/2017
4567180 7/19/20177/19/2017
45673651/19/20181/20/20181/19/2018
789030 12/3/201612/3/2016
78901806/1/20176/1/20176/1/2017
7890365 12/3/2017 
2 REPLIES 2
UdayGuntupalli
Quartz | Level 8

@radhikaa4
       If you are open to other solutions, I would like to offer the following using a data step. 

 

Data Want; 
       set Have;   /* where Have is your original dataset */
       If Missing(visit_date) Then
          Do;
             new_visit_date  = expected_visit_date; 
          End;
       Else 
          Do; 
              new_visit_date = visit_date; 
          End; 
Run; 

         The Proc SQL version might look something like this: 

 

Proc Sql;
	Create Table Want As 
		Select *,
		       Case 
		       	    When Missing(visit_date) Then expected_visit_date
		       		Else visit_date
		       	End As new_visit_date
		From Have ;
Quit;

 

Ksharp
Super User

proc sql;

 select coalesce(visit_date,expected_visit_date) as new_visit_date

  from have;

quit;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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