BookmarkSubscribeRSS Feed
doctortimi
Obsidian | Level 7

Hi all,

 

I am working on an oncology project to assess biochemical recurrence (BCR) defined as PSA >= 0.2. PSA values are collected up to 100 times with PSA dates for each value. I want to capture:

1) the first BCR value and the date it happens. 

2) the first BCR value and the date it happens (ONLY if there are 2 consecutive BCR values). 

I am trying to do this with an array and do loop. 2 variables - bcrvalue and bcrdate, will be created in the data step.

Thank you!

 

data have;
  	input ID $ psa1 psa2 psa3 psadate1 :mmddyy10. psadate2 :mmddyy10. psadate3 :mmddyy10.;
	format psadate: mmddyy10.;
  	datalines;
1 0.1 0.1 1.5 3/05/2020 08/31/2020 08/05/2021
2 0.2 . . 3/05/2021 . .
3 3.3 0.1 . 3/05/2022 08/31/2022 .
4 0.2 0.5 5.5 3/05/2021 08/31/2021 08/05/2022
;
run;

 

6 REPLIES 6
ballardw
Super User

1) the first BCR value and the date it happens.

2) the first BCR value and the date it happens (ONLY if there are 2 consecutive BCR values).

Is two different conditions. Since you don't show any with non-consecutive values then you need to show us what that would look like. And what the values of bcrvalue and bcrdate should be for an example with and without consecutive values.

 

I suspect there is something else going on that may not be clearly defined because from your example data the "first" values are always PSA1 and PSADATE1 so I am not sure where the complexity comes from. Or your representative data is not actually representative enough. Because there would be no actual use for an array as only psadate1 and psadate2 would ever be involved with satisfying the conditions.

 

doctortimi
Obsidian | Level 7

Thank you for your response.

 

For the first condition/question, bcrvalue will be 1.5, bcrdate will be 08/05/2021 for Pt 1; bcrvalue will be 0.2, bcrdate will be 03/05/2021 for Pt 2; etc

For the second condition/question, bcrvalue and bcrdate will be missing for Pt 1, 2, & 3 since they don't have 2 consecutive BCR events. Pt 4 will be evaluated for this condition because they meet the criteria - bcrvalue will be 0.2, bcrdate will be 03/05/2021.

ballardw
Super User

You say "Pt 1, 2, & 3 since they don't have 2 consecutive BCR events", but you still do not define what constitutes "consecutive".

I have to assume by PT you mean the values of ID in the example data. Please use the variable names or name your variables with the work you use in the discussion as that makes it much easier to follow.

 

I am especially confused about why PT 4, if it is indeed ID=4 qualifies when ID=1 does not. The dates are awfully similar for for ID 1 and 4 other than year. And neither seems "consecutive" to me.

 

I will accept that ID=2 is not "consecutive" as it only has one date/measurement. The values for the dates for ID=3, for the dates given are the same as ID=4 except for year and only having 2.  So you really need to define "consecutive" as it is note a normal where "consecutive" dates would be one day apart. I might accept one month apart but your Id=4 doesn't meet that either.

data have;
  	input ID $ psa1 psa2 psa3 psadate1 :mmddyy10. psadate2 :mmddyy10. psadate3 :mmddyy10.;
	format psadate: mmddyy10.;
  	datalines;
1 0.1 0.1 1.5 3/05/2020 08/31/2020 08/05/2021
2 0.2 . . 3/05/2021 . .
3 3.3 0.1 . 3/05/2022 08/31/2022 .
4 0.2 0.5 5.5 3/05/2021 08/31/2021 08/05/2022
;
run;
doctortimi
Obsidian | Level 7

Yes, I was referring to each ID as Pt (patient). I'll stay consistent with the use of ID.

 

I defined a BCR event as PSA greater than or equal to 0.2, so consecutive events are any back-to-back PSAs >= 0.2. So, you see the reason why ID 1 does not qualify. Please do not think too much about the dates being 1 day apart or 1 month apart - it's just an example. 

Kurt_Bremser
Super User

How should the two different conditions be reflected in the desired result? Do you want a report or a dataset? What if there's missing values between BCR events?

 

STRONGLY consider transposing to a long dataset layout; this is usually easier to use in further processing.

RD2
Fluorite | Level 6 RD2
Fluorite | Level 6
data have;
  input ID $ psa1 psa2 psa3 psadate1 :mmddyy10. psadate2 :mmddyy10. psadate3 :mmddyy10.;
format psadate: mmddyy10.;
  datalines;
1 0.1 0.1 1.5 3/05/2020 08/31/2020 08/05/2021
2 0.2 . . 3/05/2021 . .
3 3.3 0.1 . 3/05/2022 08/31/2022 .
4 0.2 0.5 5.5 3/05/2021 08/31/2021 08/05/2022
;
run;
 
 
/*mindate[i] carray the earliest date of psa GE 0.2;*/
data have1;
set have;
array pvalue psa1 - psa3 ;
array pdate psadate1 - psadate3;
array mindate mindt_psa1 - mindt_psa3; 
mindate[1] = ifn(pvalue[1] GE 0.2, pdate[1], .);
 
do i = 2 to dim(pvalue); 
if pvalue[i] GE 0.2 then mindate[i] = min(of mindate[i-1], pdate[i]) ;
else mindate[i] = mindate[i-1];
 
end;
format mindt_psa: MMDDYY10.;
run;
 
/*minevent[i] carray the earliest BCR event date;*/
 
data have2;
set have1;
array pvalue psa1 - psa3 ;
array pdate psadate1 - psadate3;
array minevnet minevt_psa1 - minevt_psa3;
 
minevnet[1] = .;
minevnet[2] = ifn(pvalue[1] GE 0.2 and pvalue[2] GE 0.2 , pdate[1], .);
 
do i = 3 to dim(pvalue); 
if pvalue[i-1] GE 0.2  and pvalue[i] GE 0.2 then minevnet[i] = min(of minevnet[i-1], pdate[i-1]) ;
else minevnet[i] = minevnet[i-1];
 
end;
format minevt_psa: MMDDYY10.;
run;

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 230 views
  • 0 likes
  • 4 in conversation