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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 2 replies
  • 1202 views
  • 1 like
  • 3 in conversation