BookmarkSubscribeRSS Feed
pamplemouse22
Calcite | Level 5

Hi, 

 

I am running a cox model with time-varying exposure. Exact age is the time scale and the exposure varies by calendar year. I have this code that creates the following output: 

proc  phreg  data  = dat ;
	model age* outcome(0)  =  var_pm25  edu sex center/  rl entry=age0;
	array pm25 {15} 	pm25_1999 - pm25_2013  ;
	do  i  =  1  to  15;
	if (age1999+i-1)<age<=(age1999+i) then var_pm25=  pm25[i];
	end;
run;

pamplemouse22_1-1598650568481.png

 

pamplemouse22_0-1598650551345.png

 

How can I recreate the above results, without the programming statement? I tried to include the array in a data step before the proc, and the array pulls the exposure I am interested in. but the total sample, and number of events with missing, and hazard ratio are (very) different. I think it has something to do with when the exposure is pulled. code/results below. 

data test; 
	set dat;
	array pm25 {15} 	pm25_1999 - pm25_2013  ;
	array pm25_new {15} 	_1999 - _2013  ;
	do  i  =  1  to  15;
	if (age1999+i-1)<age<=(age1999+i) then pm25_new[i]=  pm25[i]/5;
	end;
run;  

data test2; 
	set test; 
	pm25_new=sum (of _1999-_2013); 
run;

proc  phreg  data  = test2 ;
	model age* outcome(0)  =  pm25_new  edu sexe cod_cen /  rl entry=age0;
run;

pamplemouse22_2-1598650906036.pngpamplemouse22_3-1598650927783.png

 

Thank you.

11 REPLIES 11
FreelanceReinh
Jade | Level 19

Hi @pamplemouse22,

 

I think your current approach (using dataset test2) cannot work because variable pm25_new is (necessarily) constant, while it ought to be time-dependent (like var_pm25). It should be possible, however, to omit the programming statements in the PROC PHREG step if you create an input dataset with a different structure (and use the slightly different syntax for such datasets in the MODEL statement): see Counting Process Style of Input. There you have multiple observations per subject, corresponding to disjoint time intervals, which enables you to define different values of a time-dependent covariate in different time intervals.

pamplemouse22
Calcite | Level 5
Hi, Thanks for your reply. I think you are right and I am trying to change my dataset to the counting style, but am still unable to match my results. What is confusing to me is that my time scale is age, but my exposure is determined by calendar time (calendar year). I can't find a good example of this to follow.
Currently, my dataset has 1 row per person-calendar year, and there is a start age, and stop age, and pm25 value that varies for each row. This still doesn't produce the numbers I want. Suggestions?
FreelanceReinh
Jade | Level 19

If the approach using var_pm25 works, why do you want to eliminate the programming statements from the PROC PHREG step?

pamplemouse22
Calcite | Level 5

Just to see if I understand how it works, properly. I guess I don't since I am not getting numbers to match! I also have to make some small changes, and need to understand this well so I feel confident in my changes. 

FreelanceReinh
Jade | Level 19

If in doubt, I would probably do a simulation, i.e., create artificial data based on a (Cox-PH) model with known coefficients. I think a simplified model with the time-dependent covariate as the only predictor might be sufficient for this purpose. Chapter 12 of Simulating Data with SAS® should contain instructions for that, but I don't have this book yet.

pamplemouse22
Calcite | Level 5
That is a great idea, I will try that! Thanks!
Tom
Super User Tom
Super User

Why did you change the logic to divide by 5?  And then SUM?

What happens if you just use the same logic?

data test; 
	set dat;
	array pm25 {15} 	pm25_1999 - pm25_2013  ;
	do  i  =  1  to  15;
	if (age1999+i-1)<age<=(age1999+i) then var_pm25 =  pm25[i];
	end;
run;  
proc  phreg  data  = test;
	model age* outcome(0)  =  var_pm25  edu sex center/  rl entry=age0;
run;
pamplemouse22
Calcite | Level 5
Hi,

I divided by 5 since the original array also divides by 5 (this is just to change the unit increase for the final HR)

The logic you presented is a little different since the final var_pm25 would be assigned pm25[15], rather than updating for each i . So, I did it as 2 steps where a new value is created for each i, and then i took the sum to get the value i'm interested in (each row only meets the if-logic once, this can be any i 1 to 15).

Tom
Super User Tom
Super User

I don't think you understand what the DO loop was doing.

array pm25 {15} 	pm25_1999 - pm25_2013  ;
do  i  =  1  to  15;
  if (age1999+i-1)<age<=(age1999+i) then var_pm25 =  pm25[i];
end;

If was NOT generating 15 values of VAR_PM25. It was just finding which value to use based on the value of AGE compared to the value of AGE1999.   So if the subject was 50 years old in 1999 and in this records they are now 51 it will use the value from the PM_2000 variable.

pamplemouse22
Calcite | Level 5
Ah yes, I agree the above do loop creates 1 var_pm25. But, it's my understanding the do loop as a data step works differently from a do loop in a proc phreg. I'm trying to replicate the do loop in proc phreg in a data step -- suggestions? thanks!
Tom
Super User Tom
Super User

Why would the logic of a do loop be different?  The only difference I know is that in PHREG the ARRAY statement requires the 

{15}

after the array name.  In a data step SAS is smart enough the know that pm25_1999 - pm25_2013 is 15 variables without adding that extra bit of code to the ARRAY statement.

 

Did you try the code i posted? Did you get the matching results?

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 11 replies
  • 1525 views
  • 0 likes
  • 3 in conversation