Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code for Multiple Occurrences

Status
Not open for further replies.

shelby55

Technical User
Jun 27, 2003
1,229
CA
Hello

I'm using base SAS version 9.3.

I have a database where one line of data is one patient abstract. Each abstract can have from 0 to 20 procedures. There are many fields related to the procedures but for this purpose I only need to look at pxcode1-pxcode20 (the actual procedure code), pxstdate1-pxstdate20 (procedure start date) and pxsttime1-pxsttime20 (procedure start time).

The way the data is entered is that dates are only entered per episode so if procedure 1, 2, and 3 all occurred in the same episode (as determined by the date/time) then there will be a date in pxstdate1 but not in pxstdate2 or pxstdate3 OR if there is a date then it will be the same as procedure 1. If the date/time changes then it's a new episode and there could be multiple procedures for that occurrence.

Example:
px1=5MD60AA
pxstartdt1=Apr 1, 2012
px2=1RB89LA
pxstartdt2=
px3=1YM91LA
pxstartdt3=
px4=3OD70CA
pxstartdt4=April 5, 2012
In the example above px1 would be episode 1, occurrence 1; px2 would be episode 1, occurrence 2; px3 would be episode 1, occurrence 3; px4 would be episode 2, occurrence 1.

For the code below, it's wrong for many reasons including that I can't seem to figure out how to combine the singular date and time fields that are pulled in from the data source to make a date/time field so I only used date for this example. However, I need to include time because someone could have multiple procedural episodes on the same day but at a different time so just looking at date isn't accurate.

The other reason it is wrong is because if procedure 2 and 3 are in the same episode then the "is blank" needs to address that epi3 should be "2" and not "1".

Code:
if PxStDate1 ge '01Apr00'd then epi1="1";

if Px2 ne "" and (PxStDate2 eq "" or PxStDate2 eq PxStDate1)
then epi2="1";
else if Px2 ne "" and PxStDate2 ge '01Apr00'd and PxStDate2 ne PxStDate1
then epi2="2";
else epi2="";

if Px3 ne "" and (PxStDate3 eq "" or PxStDate3 eq PxStDate1)
then epi3="1";
if Px3 ne "" and (PxStDate3 eq "" or PxStDate3 eq PxStDate2)
then epi3="2";
else if Px3 ne "" and PxStDate3 ge '01Apr00'd and PxStDate3 ne PxStDate1 and
PxStDate3 ne PxStDate2 then epi3="3";
else epi3="";

Any assistance greatly appreciated.
 
Hi,

I am not clear on the last part you have mentioned " The other reason it is wrong is because if procedure 2 and 3 are in the same episode then the "is blank" needs to address that epi3 should be "2" and not "1". "

But for converting adding time into date; I can say the following.

You have not mentioned in which format you are currently getting the date-time value from external database.
But if you can treat it as simple string then using simple string function like SUBSTR() you can separate each part of the field like date, hours, minutes and seconds and then use DHMS () function to convert it into SAS date-time format.

For details on DHMS () function you can visit [URL unfurl="true"]https://sites.google.com/site/sasbuddy/sas-date-function-dhms[/url].

Hope it will help you.

Regards,


sasbuddy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top