<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: define time dependent variable in proc phreg in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604326#M29374</link>
    <description>I am using the following procedure.&lt;BR /&gt;&lt;BR /&gt;proc phreg data=ag16g covsandwich(aggregate);&lt;BR /&gt;ID caseidno;&lt;BR /&gt;model daystorept2*inrept2(0)=cntc30chld /ties=breslow;&lt;BR /&gt;/*if daystorept2-daystochcntc=. or daystorept2-daystochcntc&amp;gt;30 then cntc30chld=0; else cntc30chld=1; */&lt;BR /&gt;if 0&amp;lt;=daystorept2-daystochcntc &amp;lt;= 30 then cntc30chld=1; else cntc30chld=0;&lt;BR /&gt;run;</description>
    <pubDate>Thu, 14 Nov 2019 22:06:57 GMT</pubDate>
    <dc:creator>Sophie87</dc:creator>
    <dc:date>2019-11-14T22:06:57Z</dc:date>
    <item>
      <title>define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604123#M29358</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;My cox model includes a time-dependent variable. I tried different ways to define the variable in proc phreg procedure (after model statement) but got very different results. Please help me!&lt;/P&gt;&lt;P&gt;The first way, I defined 0 first and else=1 and got hazard ration of .47 which made sense.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="caret-color: #000000; color: #000000; font-family: 'DejaVu Sans'; font-size: 13.3333px; font-style: normal; font-variant-caps: normal; letter-spacing: normal; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline !important; float: none;"&gt;if daystorept2-daystochcntc=. or daystorept2-daystochcntc&amp;gt;30 then cntc30chldadj=0; else cntc30chldadj=1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="caret-color: #000000; color: #000000; font-family: 'DejaVu Sans'; font-size: 13.3333px; font-style: normal; font-variant-caps: normal; letter-spacing: normal; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline !important; float: none;"&gt;The second way, i defined 1 first and else=0 and got HR=5.6 which totally did not make sense.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="caret-color: #000000; color: #000000; font-family: 'DejaVu Sans'; font-size: 13.3333px; font-style: normal; font-variant-caps: normal; letter-spacing: normal; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline !important; float: none;"&gt;if 0&amp;lt;=daystorept2-daystochcntc &amp;lt;= 30 then cntc30chld=1; else cntc30chld=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="caret-color: #000000; color: #000000; font-family: 'DejaVu Sans'; font-size: 13.3333px; font-style: normal; font-variant-caps: normal; letter-spacing: normal; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline !important; float: none;"&gt;I checked frequencies of the two variables and they are exactly the same. So why did I get so different results. Anyone know? How does SAS process the statement in proc phreg?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="caret-color: #000000; color: #000000; font-family: 'DejaVu Sans'; font-size: 13.3333px; font-style: normal; font-variant-caps: normal; letter-spacing: normal; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline !important; float: none;"&gt;Thank you!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 14:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604123#M29358</guid>
      <dc:creator>Sophie87</dc:creator>
      <dc:date>2019-11-14T14:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604272#M29359</link>
      <description>&lt;P&gt;Hey Sophie,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take a look at the illustration I have below. I think you may be having a discrepancy in which observations get grouped in your two methods.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(drop=i);
	val=0;
	do i=1 to 40;
		if i le 5 then do;
			val=.;
			output;
		end;
		else do;
			val=i-8;
			output;
		end;
	end;
run;

proc format;
	value opt_a
	low-30 = 1
	other = 0
	;
	value opt_b
	0-30 = 1
	other = 0
	;
run;

data check;
set have;
chk1=input(put(val,opt_a.),8.);
chk2=input(put(val,opt_b.),8.);
run;

data issue_vals;
set check(where=(chk1 ne chk2));
run;

proc print data=issue_vals;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Negative values will be in different buckets depending on the logic you use. Does this help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-unison&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 20:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604272#M29359</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-14T20:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604297#M29362</link>
      <description>&lt;P&gt;Thank you very much for your help. To be honest, I am not really clear how this relates to my problem. I checked frequencies using two different definitions, and the frequencies were exactly the same. But the results of proc phreg precedure gives conflicting info. I am very confused. Could you explain more? Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 21:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604297#M29362</guid>
      <dc:creator>Sophie87</dc:creator>
      <dc:date>2019-11-14T21:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604302#M29363</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To be clear, you did something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=option1; tables cntc30chld; run;

proc freq data=option2; tables cntc30chld; run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By checking the frequency I was under the impression you did it for your set in total rather than by cntc30chld. What I was getting at in the above example is that the two bucketing methods yield different results if you have values below 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide sample data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-unison&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 21:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604302#M29363</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-14T21:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604303#M29364</link>
      <description>you mean, do a cross tab table of the two variables? Let me check that! Thank you so much for your quick response!</description>
      <pubDate>Thu, 14 Nov 2019 21:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604303#M29364</guid>
      <dc:creator>Sophie87</dc:creator>
      <dc:date>2019-11-14T21:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604306#M29366</link>
      <description>&lt;P&gt;Yes and not a problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I edited my reply above to add more context to my example.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 21:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604306#M29366</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-14T21:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604307#M29367</link>
      <description>Just checked, they were exactly the same variable.</description>
      <pubDate>Thu, 14 Nov 2019 21:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604307#M29367</guid>
      <dc:creator>Sophie87</dc:creator>
      <dc:date>2019-11-14T21:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604311#M29368</link>
      <description>&lt;P&gt;So the 2 bucketing methods yielded the same number of observations for&amp;nbsp;cntc30chld=1 and&amp;nbsp;cntc30chld=0?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do&amp;nbsp;&lt;SPAN&gt;daystorept2 and&amp;nbsp;daystochcntc represent?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 21:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604311#M29368</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-14T21:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604312#M29369</link>
      <description>it's the gap between "survival time" (days to report) and days to contact date.</description>
      <pubDate>Thu, 14 Nov 2019 21:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604312#M29369</guid>
      <dc:creator>Sophie87</dc:creator>
      <dc:date>2019-11-14T21:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604315#M29370</link>
      <description>&lt;P&gt;Okay that's helpful. Can you produce a sample set removing any sensitive information? It's difficult to reproduce the issue without the input. Also, any relevant options you are using in proc phreg.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 21:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604315#M29370</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-14T21:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604317#M29371</link>
      <description>Thank you! Let me prepare that! Thank you for your time and patience!</description>
      <pubDate>Thu, 14 Nov 2019 21:43:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604317#M29371</guid>
      <dc:creator>Sophie87</dc:creator>
      <dc:date>2019-11-14T21:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604318#M29372</link>
      <description>&lt;P&gt;Here's a great article that may streamline things:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 21:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604318#M29372</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-14T21:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604325#M29373</link>
      <description>Obs caseidno daystorept2 inrept2 daystochcntc&lt;BR /&gt;&lt;BR /&gt;1 00010003 114 0 88&lt;BR /&gt;2 00011404 183 0 .&lt;BR /&gt;3 00011405 183 0 .&lt;BR /&gt;4 00021203 110 0 .&lt;BR /&gt;5 00021204 110 0 .&lt;BR /&gt;6 00021205 110 0 .&lt;BR /&gt;7 00021206 183 0 .&lt;BR /&gt;8 00021207 183 0 .&lt;BR /&gt;9 00021208 183 0 .&lt;BR /&gt;10 00021208 110 0 .&lt;BR /&gt;11 00021403 3 0 .&lt;BR /&gt;12 00021403 183 0 .&lt;BR /&gt;13 00021404 3 0 .&lt;BR /&gt;14 00021404 183 0 .&lt;BR /&gt;15 00021405 3 0 .&lt;BR /&gt;16 00021405 183 0 .&lt;BR /&gt;17 00021503 183 0 .&lt;BR /&gt;18 00021503 71 0 .&lt;BR /&gt;19 00021504 183 0 .&lt;BR /&gt;20 00021504 71 0 .&lt;BR /&gt;21 00021505 1 0 .&lt;BR /&gt;22 00021505 183 0 .&lt;BR /&gt;23 00021505 20 0 .&lt;BR /&gt;24 00031303 4 0 .&lt;BR /&gt;25 00031303 183 0 .&lt;BR /&gt;26 00031403 111 0 .&lt;BR /&gt;28 00031403 11 1 .&lt;BR /&gt;29 00031403 50 0 .&lt;BR /&gt;30 00031403 183 0 .&lt;BR /&gt;31 00031503 183 0 .&lt;BR /&gt;32 00031504 183 0 .&lt;BR /&gt;33 00031505 183 0 .&lt;BR /&gt;34 00031505 135 0 .&lt;BR /&gt;35 00031506 183 0 .&lt;BR /&gt;36 00031506 135 0 .&lt;BR /&gt;37 00051103 183 0 .&lt;BR /&gt;38 00051104 183 0 .&lt;BR /&gt;39 00051105 183 0 .&lt;BR /&gt;40 00051204 183 0 174&lt;BR /&gt;41 00051204 183 0 178&lt;BR /&gt;42 00051204 183 0 180&lt;BR /&gt;43 00051204 21 0 17&lt;BR /&gt;44 00051204 183 0 182</description>
      <pubDate>Thu, 14 Nov 2019 22:06:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604325#M29373</guid>
      <dc:creator>Sophie87</dc:creator>
      <dc:date>2019-11-14T22:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604326#M29374</link>
      <description>I am using the following procedure.&lt;BR /&gt;&lt;BR /&gt;proc phreg data=ag16g covsandwich(aggregate);&lt;BR /&gt;ID caseidno;&lt;BR /&gt;model daystorept2*inrept2(0)=cntc30chld /ties=breslow;&lt;BR /&gt;/*if daystorept2-daystochcntc=. or daystorept2-daystochcntc&amp;gt;30 then cntc30chld=0; else cntc30chld=1; */&lt;BR /&gt;if 0&amp;lt;=daystorept2-daystochcntc &amp;lt;= 30 then cntc30chld=1; else cntc30chld=0;&lt;BR /&gt;run;</description>
      <pubDate>Thu, 14 Nov 2019 22:06:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604326#M29374</guid>
      <dc:creator>Sophie87</dc:creator>
      <dc:date>2019-11-14T22:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604367#M29377</link>
      <description>&lt;P&gt;Okay, with the data you provided, I wasn't able to reproduce the same issue. I adjusted the data to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(drop=obs);
input obs caseidno daystorept2 inrept2 daystochcntc;
datalines;
1 00010003 114 0 88
2 00011404 183 1 77
3 00011405 183 0 77
4 00021203 110 0 77
5 00021204 110 0 77
6 00021205 110 1 77
7 00021206 183 0 .
8 00021207 183 0 .
9 00021208 183 0 77
10 00021208 110 0 .
11 00021403 3 0 .
12 00021403 183 1 44
13 00021404 3 0 .
14 00021404 183 0 44
15 00021405 3 0 .
16 00021405 183 1 .
17 00021503 183 1 .
18 00021503 71 0 .
19 00021504 183 0 .
20 00021504 71 0 .
21 00021505 1 0 .
22 00021505 183 1 .
23 00021505 20 0 .
24 00031303 4 0 .
25 00031303 183 1 .
26 00031403 111 0 .
28 00031403 11 1 9
29 00031403 50 0 .
30 00031403 183 0 .
31 00031503 183 0 77
32 00031504 183 0 .
33 00031505 183 0 77
34 00031505 135 0 .
35 00031506 183 0 44
36 00031506 135 0 .
37 00051103 183 0 .
38 00051104 183 0 152
39 00051105 183 0 .
40 00051204 183 0 174
41 00051204 183 0 178
42 00051204 183 0 180
43 00051204 21 0 17
44 00051204 183 0 182
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then ran:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data intermediate;
set have;
if daystorept2-daystochcntc=. or daystorept2-daystochcntc&amp;gt;30 then flag1=0;
else flag1=1;
if 0&amp;lt;=daystorept2-daystochcntc &amp;lt;= 30 then flag2=1; 
else flag2=0;
run;

proc phreg data=intermediate covsandwich(aggregate);
ID caseidno;
model daystorept2*inrept2(0)=flag1 /ties=breslow;
run;

proc phreg data=intermediate covsandwich(aggregate);
ID caseidno;
model daystorept2*inrept2(0)=flag2 /ties=breslow;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And was still unable to replicate the issue. Can you try running the second part of the real data and report back as to whether or not this remedies the issue? Note the 'intermediate' step -- I pull your&amp;nbsp;&lt;SPAN&gt;cntc30chld&lt;/SPAN&gt; logic out the the proc phreg procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-unison&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 01:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/604367#M29377</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-15T01:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: define time dependent variable in proc phreg</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/605885#M29426</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299645"&gt;@Sophie87&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for the late reply. I was just wondering if you've resolved the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270457"&gt;@unison&lt;/a&gt;'s first response already provided the reason why the two definitions in your initial post lead to very different results: Whenever &lt;FONT face="courier new,courier"&gt;&amp;nbsp;. &amp;lt; daystorept2 &amp;lt; daystochcntc&lt;/FONT&gt;&amp;nbsp;(i.e., the difference is negative), the time-dependent variable is defined to be 1 by the first definition, but 0 by the second.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299645"&gt;@Sophie87&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN style="caret-color: #000000; color: #000000; font-family: 'DejaVu Sans'; font-size: 13.3333px; font-style: normal; font-variant-caps: normal; letter-spacing: normal; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline !important; float: none;"&gt;I checked frequencies of the two variables and they are exactly the same.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm sure that you "checked" the frequencies after you computed the&amp;nbsp;time-dependent variable in a DATA (or PROC SQL) step where you applied either definition to each of the observations in dataset&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;ag16g&lt;/FONT&gt; (i.e., the input dataset of your PROC PHREG step). &lt;EM&gt;Then&lt;/EM&gt; it is not surprising that the frequencies didn't differ because most likely there are no cases with&amp;nbsp;&lt;FONT face="courier new,courier"&gt;daystorept2 &amp;lt; daystochcntc&lt;/FONT&gt; in your data (since, I assume, the "contact" simply &lt;EM&gt;cannot&lt;/EM&gt; occur after the "event" time, nor after censoring). At least this is true for the sample data you've posted.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;EM&gt;But&lt;/EM&gt; this "check" ignores that the computation of the &lt;A href="https://documentation.sas.com/?docsetId=statug&amp;amp;docsetTarget=statug_phreg_details05.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_blank" rel="noopener"&gt;partial likelihood function&lt;/A&gt;&amp;nbsp;involves evaluations of the time-dependent variable &lt;EM&gt;&lt;STRONG&gt;at each event time&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;(and this is what PROC PHREG does with those "programming statements" after the MODEL statement)! The algorithm "looks back" at the event time &lt;EM&gt;of a different subject&lt;/EM&gt;&amp;nbsp;(who experienced their event earlier after "time zero" in the study) and computes the time-dependent variable for the subject at hand (using &lt;EM&gt;their&lt;/EM&gt;&amp;nbsp;"days to contact"). Of course, &lt;EM&gt;that&amp;nbsp;other&lt;/EM&gt; event might very well have happened "before" the contact date of the subject at hand. Hence, a negative difference &lt;EM&gt;does&lt;/EM&gt; occur and this is where the difference between your two definitions becomes relevant.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It's probably not easy to notice that intricacy by a quick look at the formulas in the PROC PHREG documentation (linked above), but it's explained very well in Paul Allison's&amp;nbsp;&lt;A href="https://www.sas.com/store/books/categories/usage-and-reference/survival-analysis-using-sas-a-practical-guide-second-edition/prodBK_61339_en.html" target="_blank" rel="noopener"&gt;Survival Analysis Using SAS®: A Practical Guide&lt;/A&gt; (p. 140 f. in my older, &lt;EM&gt;first&lt;/EM&gt; edition).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270457" target="_blank" rel="noopener"&gt;unison&lt;/A&gt;'s suggestion of "pulling" the definition of the time-dependent explanatory variable out of the PROC PHREG step could be implemented, &lt;EM&gt;but&lt;/EM&gt; would require a different structure of the input dataset (see &lt;A href="https://documentation.sas.com/?docsetId=statug&amp;amp;docsetTarget=statug_phreg_details12.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_blank" rel="noopener"&gt;Counting Process Style of Input&lt;/A&gt;) -- and should yield exactly the same results as your current code, so you really don't need to do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Now the question arises: Which of the two definitions (if any) is correct? Without deeper knowledge of your study I would think of those "contacts" as occurrences which may have an impact on the subjects' hazard of experiencing the target event. After all, this is exactly why you would consider them in the Cox model. I think your definitions and sample data suggest that you expect the "contact" to modify the hazard function only during a 30-day period after the contact (which sounds plausible). However, wouldn't this imply that &lt;EM&gt;before&lt;/EM&gt; the contact the impact of the contact should be zero (like in cases where no contact occurred, i.e. &lt;FONT face="courier new,courier"&gt;daystochcntc=.&lt;/FONT&gt;), hence that the second definition should be preferred? But unfortunately this is the one whose resulting hazard ratio "totally did not make sense," as you wrote.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Of course, knowing your study much better than me, you may arrive at a different conclusion.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I don't know, for example, how to interpret the multiple occurrences of some CASEIDNOs in your sample dataset (maybe &lt;A href="https://documentation.sas.com/?docsetId=statug&amp;amp;docsetVersion=14.3&amp;amp;docsetTarget=statug_phreg_examples11.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;clustered data&lt;/A&gt;?). Nevertheless I hope that the above explanations are helpful.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 18:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/define-time-dependent-variable-in-proc-phreg/m-p/605885#M29426</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-11-20T18:51:23Z</dc:date>
    </item>
  </channel>
</rss>

