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

 

if first.patid then call missing(difference);
if difference = . or difference <= 180 then ep = 0;
ep + 1;

Here is the sample data:

 

PatID.        FirstDayofService.         LastDayofService.  Difference Episode

AB12015-10-312015-10-31.1
AB12016-05-142016-05-141962
AB12017-12-132017-12-135783
AB12017-12-132017-12-1301
AB12017-12-132017-12-1301

 

In this sample data, I am calculating the difference between first day of service and next first day of service. If the difference is 0 or < 180 days then I am trying to add the same episode. Else Episode will increase by 1. For the first three rows highlighted in green, its working correctly. For the next two rows, highlighted in orange, it's not working correctly as its incorrectly showing episode as 1. It should take the episode based on previous episode value. i.e. 3 if the difference is less than 180. In this case the correct response for last two rows in episode column should be 3. 

 

Please help me out.

1 ACCEPTED SOLUTION

Accepted Solutions
chandan_mishra
Obsidian | Level 7

@andreas_lds 

 

Thank you for your response. When I use the fix below, I am getting the correct logic but not the correct result:

 

chandan_mishra_0-1644588046225.png

Episode should show 1,2,3,3,3, Here it is starting at 0. 

 

I tried changing the initial value of episode to 1,

rsubmit;
data check1;
	set check;
	by FDS;/*First day of Service*/
if first.patid then do;
  difference = 0;
  episode = 1;
end;

if difference > 180 then episode +1;
run;
endrsubmit;

But even then its showing the same results. 

View solution in original post

3 REPLIES 3
andreas_lds
Jade | Level 19

If the difference is 0 or < 180 days then I am trying to add the same episode.

Right know your code does the opposite:

if difference = . or difference <= 180 then ep = 0;

 A fix could be:

if first.patid then do;
  difference = 0;
  ep = 0;
end;

if difference > 180 then ep +1;

chandan_mishra
Obsidian | Level 7

@andreas_lds 

 

Thank you for your response. When I use the fix below, I am getting the correct logic but not the correct result:

 

chandan_mishra_0-1644588046225.png

Episode should show 1,2,3,3,3, Here it is starting at 0. 

 

I tried changing the initial value of episode to 1,

rsubmit;
data check1;
	set check;
	by FDS;/*First day of Service*/
if first.patid then do;
  difference = 0;
  episode = 1;
end;

if difference > 180 then episode +1;
run;
endrsubmit;

But even then its showing the same results. 

chandan_mishra
Obsidian | Level 7
Sorry skip this previous message. Figured it out. Didnt add proc sort by patid and fds.

rsubmit;
proc sort data=UASADHOC
out=check;
by PATID fds;
run;
endrsubmit;

rsubmit;
data check1;
set check;
by PATID FDS;
if first.PatID then do;
difference = 0;
episode = 1;
end;

if difference > 180 then episode +1;
run;
endrsubmit;

Its working now.

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!

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